<?php

namespace app\admin\service\user_profile\userArchive\basicInfo;

use app\admin\service\user_profile\userArchive\crisisTesting\CrisisTestingService;
use app\admin\service\user_profile\userArchive\evaluationArchive\EvaluationArchiveService;
use app\admin\service\user_profile\userArchive\psychologicalCounseling\PsychologicalCounselingService;
use app\admin\service\user_profile\userArchive\selfTesting\SelfTestingService;
use app\admin\service\UserService;
use app\common\Message;
use app\model\archives_model\UserArchiveModel;
use app\model\archives_model\UserArchiveOptionModel;
use app\model\archives_model\UserArchiveTemplateModel;
use app\model\UserModel;
use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\TemplateProcessor;
use think\db\BaseQuery;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
use think\Service;

class BasicInfoService extends Service
{
    use Message;

    /**
     * @param $data
     * @return true
     * @throws DbException
     * @throws DataNotFoundException
     * @throws ModelNotFoundException|Exception
     */
    public function exportBasicInfo($data): bool
    {
        $key = ['menu','type','user_id'];
        foreach($key as $item){
            if(!check_array_key($item,$data)){
                $this->message = '缺少参数！';
                return false;
            }
        }
        if($data['role_mode']>2){
            $this->message = '暂无权限还原！';
            return false;
        }
        switch ($data['menu']){
            case 1:
                //用户基本信息
                switch ($data['type']) {
                    case 0:
                        //导出所有档案
                        $basic_info = $this->basicInfo($data); //基本信息
                        $data['type'] = 2;
                        $get_Health_info = $this->getHealthInfo($data); //健康情况
                        $data['type'] = 3;
                        $get_education_info = $this->getEducationInfo($data); //教育情况
                        $data['type'] = 4;
                        $get_disability_leve_info = $this->getDisabilityLevelInfo($data);//残障等级
                        $data['type'] = 5;
                        $get_family_situation_info = $this->getFamilySituationInfo($data); //家庭情况
                        $data['type'] = 6;
                        $get_family_interviews_info = $this->getFamilyInterviewsInfo($data); //家庭访谈
                        $data['type'] = 7;
                        $get_mental_state_info = $this->getMentalStateInfo($data); //精神状态
//                        if(empty($basic_info) && empty($get_Health_info) && empty($get_education_info) && empty($get_disability_leve_info)
//                            && empty($get_family_situation_info) && empty($get_family_interviews_info) && empty($get_mental_state_info)
//                        ){
//                            $this->message = '暂无数据！';
//                            return false;
//                        }else{
                            $all['basic_info'] = $basic_info;
                            $all['get_Health_info'] = $get_Health_info!=false?$get_Health_info:'';
                            $all['get_education_info'] = $get_education_info!=false?$get_education_info:'';
                            $all['get_disability_leve_info'] = $get_disability_leve_info!=false?$get_disability_leve_info:'';
                            $all['get_family_situation_info'] = $get_family_situation_info!=false?$get_family_situation_info:'';
                            $all['get_family_interviews_info'] = $get_family_interviews_info!=false?$get_family_interviews_info:'';
                            $all['get_mental_state_info'] = $get_mental_state_info!=false?$get_mental_state_info:'';
                            $ret = $this->exportAllBasicInfo($all);
                            break;
//                        }
                    case 1:
                        // 导出基本信息
                        $basic_info = $this->basicInfo($data);
//                        $ret = $this->exportBasicDetail($basic_info);
//                        if(!empty($basic_info)){
                            //开始导出
                            $ret = $this->exportBasicDetail($basic_info);
                            break;
//                        }else{
//                            $this->result = 0;
//                            $this->message = '暂无数据！';
//                            return false;
//                        }
                    case 2:
                        // 导出健康情况
                        $get_Health_info = $this->getHealthInfo($data);
//                        if(!empty($get_Health_info)){
//                            //开始导出
                            $ret = $this->exportHealthDetail($get_Health_info);
                            break;
//                        }else{
//                            $this->message = $this->getMessage();
//                            return false;
//                        }
                    case 3:
                        // 导出教育情况
                        $get_education_info = $this->getEducationInfo($data);
//                        if(!empty($get_education_info)){
                            //开始导出
                            $ret = $this->exportEducationDetail($get_education_info);
                            break;
//                        }else{
//                            $this->message = $this->getMessage();
//                            return false;
//                        }
                    case 4:
                        // 导出残障等级
                        $get_disability_leve_info = $this->getDisabilityLevelInfo($data);
//                        if(!empty($get_disability_leve_info)){
                            //开始导出
                            $ret = $this->exportDisabilityLeve($get_disability_leve_info);
                            break;
//                        }else{
//                            $this->message = $this->getMessage();
//                            return false;
//                        }
                    case 5:
                        // 导出家庭情况
                        $get_family_situation_info = $this->getFamilySituationInfo($data);
//                        if(!empty($get_family_situation_info)){
                            //开始导出
                            $ret = $this->exportFamilySituation($get_family_situation_info);
                            break;
//                        }else{
//                            $this->message = $this->getMessage();
//                            return false;
//                        }
                    case 6:
                        // 导出家庭访谈
                        $get_family_interviews_info = $this->getFamilyInterviewsInfo($data);
//                        if(!empty($get_family_interviews_info)){
                            //开始导出
                            $ret = $this->exportFamilyInterviews($get_family_interviews_info);
                            break;
//                        }else{
//                            $this->message = $this->getMessage();
//                            return false;
//                        }
                    case 7:
                        // 导出精神状态
                        $get_mental_state_info = $this->getMentalStateInfo($data);
//                        if(!empty($get_mental_state_info)){
                            //开始导出
                            $ret = $this->exportMentalState($get_mental_state_info);
                            break;
//                        }else{
//                            $this->message = $this->getMessage();
//                            return false;
//                        }
                    default:
                        $this->message = '参数错误，暂无此分类！';
                        return false;
                }
                break;
            case 2:
                //个人自评档案
                switch ($data['type']){
                    case 0:
                        //导出所有档案
                        $self_evaluation_info = $this->selfEvaluationInfo($data);// 导出自评档案概况
                        $self_evaluation_record_info = $this->selfEvaluationRecordInfo($data);//导出个人自评记录
                        if(empty($self_evaluation_info) && empty($self_evaluation_record_info)){
                            $this->message = '暂无数据！';
                            return false;
                        }else{
                            $all['self_evaluation_info'] = $self_evaluation_info;
                            $all['self_evaluation_record_info'] = $self_evaluation_record_info;
                            $ret = $this->exportAllSelfEvaluation($all);
                            break;
                        }
                    case 1:
                        // 导出自评档案概况
                        $self_evaluation_info = $this->selfEvaluationInfo($data);
                        if(!empty($self_evaluation_info)){
                            //开始导出
                            $ret = $this->exportSelfEvaluation($self_evaluation_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    case 2:
                        //导出个人自评记录
                        $self_evaluation_record_info = $this->selfEvaluationRecordInfo($data);
                        if(!empty($self_evaluation_record_info)){
                            //开始导出
                            $ret = $this->exportSelfEvaluationRecord($self_evaluation_record_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    default:
                        $this->message = '参数错误，暂无此分类！';
                        return false;
                }
                break;
            case 3:
                //测评档案
                switch ($data['type']){
                    case 0:
                        //导出所有测评档案
                        $evaluation_info = $this->evaluationInfo($data);// 导出测评档案概况
                        $evaluation_record_info = $this->EvaluationRecordInfo($data); //导出自我测评记录
                        $task_evaluation_record_info = $this->taskEvaluationRecordInfo($data); //导出任务测评记录
                        $others_evaluation_record_info = $this->othersEvaluationRecordInfo($data);//导出他人代评记录
                        if(empty($evaluation_info) && empty($evaluation_record_info) && empty($task_evaluation_record_info) && empty($others_evaluation_record_info)){
                            $this->message = '暂无数据！';
                            return false;
                        }else{
                            $all['evaluation_info'] = $evaluation_info;
                            $all['evaluation_record_info'] = $evaluation_record_info;
                            $all['task_evaluation_record_info'] = $task_evaluation_record_info;
                            $all['others_evaluation_record_info'] = $others_evaluation_record_info;
                            $ret = $this->exportAllScaleRecord($all);
                            break;
                        }
                    case 1:
                        // 导出测评档案概况
                        $evaluation_info = $this->evaluationInfo($data);
                        if(!empty($evaluation_info)){
                            //开始导出
                            $ret = $this->exportEvaluation($evaluation_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    case 2:
                        //导出自我测评记录
                        $evaluation_record_info = $this->EvaluationRecordInfo($data);
                        if(!empty($evaluation_record_info)){
                            //开始导出
                            $ret = $this->exportEvaluationRecord($evaluation_record_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    case 3:
                        //导出任务测评记录
                        $task_evaluation_record_info = $this->taskEvaluationRecordInfo($data);
                        if(!empty($task_evaluation_record_info)){
                            //开始导出
                            $ret = $this->exportTaskEvaluationRecord($task_evaluation_record_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    case 4:
                        //导出他人代评记录
                        $others_evaluation_record_info = $this->othersEvaluationRecordInfo($data);
                        if(!empty($others_evaluation_record_info)){
                            //开始导出
                            $ret = $this->exportOthersEvaluationRecord($others_evaluation_record_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    case 5:
                        //导出无线测评记录
                        $wireless_evaluation_record_info = [];
                        if(!empty($wireless_evaluation_record_info)){
                            //开始导出
                            $ret = [];//$this->exportWirelessEvaluationRecord($wireless_evaluation_record_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    default:
                        $this->message = '参数错误，暂无此分类！';
                        return false;
                }
                break;
            case 4:
                //危机干预档案
                switch ($data['type']){
                    case 0:
                        //导出所有危机干预档案
                        $interfere_info = $this->interfereInfo($data);// 导出危机干预概况
                        $interfere_record_info = $this->interfereRecordInfo($data);//导出危机干预记录

                        if(empty($interfere_info) && empty($interfere_record_info)){
                            $this->message = '暂无数据！';
                            return false;
                        }else{
                            $all['interfere_info'] = $interfere_info;
                            $all['interfere_record_info'] = $interfere_record_info;
                            $ret = $this->exportAllInterfereRecord($all);
                            break;
                        }
                    case 1:
                        // 导出危机干预概况
                        $interfere_info = $this->interfereInfo($data);
                        if(!empty($interfere_info)){
                            //开始导出
                            $ret = $this->exportInterfere($interfere_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    case 2:
                        //导出危机干预记录
                        $interfere_record_info = $this->interfereRecordInfo($data);
                        if(!empty($interfere_record_info)){
                            //开始导出
                            $ret = $this->exportInterfereRecord($interfere_record_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    default:
                        $this->message = '参数错误，暂无此分类！';
                        return false;
                }
                break;
            case 5:
                //咨询预约档案
                switch ($data['type']){
                    case 0:
                        //导出所有咨询预约档案
                        $consult_info = $this->consultInfo($data);// 导出咨询预约概况
                        $onlineInfo_info = $this->onlineInfo($data);//导出线上咨询记录
                        $offline_info = $this->offlineInfo($data);//导出线下咨询记录
                        if(empty($consult_info) && empty($onlineInfo_info) && empty($offline_info)){
                            $this->message = '暂无数据！';
                            return false;
                        }else{
                            $all['consult_info'] = $consult_info;
                            $all['onlineInfo_info'] = $onlineInfo_info;
                            $all['offline_info'] = $offline_info;
                            $ret = $this->exportOfflineAll($all);
                            break;
                        }
                    case 1:
                        // 导出咨询预约概况
                        $consult_info = $this->consultInfo($data);
                        if(!empty($consult_info)){
                            //开始导出
                            $ret = $this->exportConsult($consult_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    case 2:
                        //导出线上咨询记录
                        $onlineInfo_info = $this->onlineInfo($data);
                        if(!empty($onlineInfo_info)){
                            //开始导出
                            $ret = $this->exportOnline($onlineInfo_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    case 3:
                        //导出线下咨询记录
                        $offline_info = $this->offlineInfo($data);
                        if(!empty($offline_info)){
                            //开始导出
                            $ret = $this->exportOffline($offline_info);
                            break;
                        }else{
                            $this->result = 0;
                            $this->message = '暂无数据！';
                            return false;
                        }
                    default:
                        $this->message = '参数错误，暂无此分类！';
                        return false;
                }
                break;
            default:
                $this->message = '参数错误，暂无此分类！';
                return false;
        }
        $this->result = $ret;
        $this->message = '操作成功！';
        return true;
    }

    /**
     * 档案用户基础信息
     * @param $data
     * @return array|BaseQuery|Model|null
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function basicInfo($data): array|BaseQuery|Model|null
    {
        $field = 'id,name,sex,age,unit_id,department_id,user_number,student_status,id_card,birthday,phone,native_place,political_outlook,
            nation,marital_status,career,interest,address,unit_id,update_time,repeal_time,time';
        $list = UserModel::query()->where('id',$data['user_id'])
            ->with(['departmentNameMode' => function($query){
                $query->with(['departmentLevel']);
            },'unitName'])
            ->field($field)->find();
        if(!empty($list)){
            if(!empty($list['level_rules'])){
                $list['level_rules'] = json_decode($list['level_rules']);
                if($list['level_rules']){
                    $list['level_rules_name'] = $list['level_rules'][$list['department_stage']];
                }else{
                    $list['level_rules_name'] = '';
                }
            }else{
                $list['level_rules_name'] = '';
            }
            //获取部门名称
            $UserService = new UserService($this->app);
            $DepartmentAffiliationAll = $UserService->getDepartmentAffiliationAll($list['unit_id']);
            $list['department_name'] = $DepartmentAffiliationAll[$list['department_id']]['name']??'';
            $list['marital_status'] = empty($list['marital_status'])?0:$list['marital_status'];
            $list['political_outlook'] = empty($list['political_outlook'])?0:$list['political_outlook'];
            $list['student_status'] = empty($list['student_status'])?0:$list['student_status'];
            $list = $list->toArray();
        }
        return $list;
    }

    /**
     * 获取性别
     * @param $data
     * @return string
     */
    private function getSex($data): string
    {
        $sex = match ($data['sex'] ?? 0) {
            0 => ' ',
            1 => '男',
            default => '女',
        };
        return $sex;
    }

    /**
     * 导出基础信息
     * @param $data
     * @return string
     */
    public function exportBasicDetail($data): string
    {
        $sex = $this->getSex($data);
        $tempInfo = new UserService($this->app);
        $studentStatus = $tempInfo->getStudentStatusSelector();//获取所有学籍状态
        $politicalOutlook = $tempInfo->getPoliticalOutlookSelector();//获取所有政治面貌
        $nation = $tempInfo->getNationSelector();//获取所有民族
        $maritalStatus = $tempInfo->getMaritalStatusSelector();//获取所有婚姻状况
//        var_dump($data);die;
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/BasicDetail.docx');
        $templateProcessor->setValue('title', '基础资料'); // 档案标题
        if(!empty($data['update_time'])){
            $update_time = $data['update_time'];
        }else{
            $update_time = $data['time']??0;
        }
        $templateProcessor->setValue('end_time', $update_time ? date('Y年m月d日',$update_time) : ' '); // 档案最后更新时间
        $templateProcessor->setValue('name', $data['name']??' '); // 姓名
        $templateProcessor->setValue('sex', $sex); // 性别
        $templateProcessor->setValue('age', $data['age']??' '); // 年龄
        $templateProcessor->setValue('unit_name', $data['unit_name']??' '); // 所在单位
        $templateProcessor->setValue('department', $data['department_name']??' '); // 所在部门
        $templateProcessor->setValue('number', $data['student_status']??' '); // 编号
        $templateProcessor->setValue('mode_name', $data['mode_name']??' '); // 学制类型
        $templateProcessor->setValue('rules_name', $data['level_rules_name']??' '); // 当前年级
        $templateProcessor->setValue('student', $studentStatus[$data['student_status']]['value']??' '); // 学籍状态
        $templateProcessor->setValue('id_card', $data['id_card']??' '); // 身份证号
        $templateProcessor->setValue('birthday', !empty($data['birthday'])?date('Y-m-d', strtotime($data['birthday'])):$data['birthday']??' '); // 出生日期
        $templateProcessor->setValue('phone', $data['phone']??' '); // 联系方式
        $templateProcessor->setValue('native_place', $data['native_place']??' '); // 籍贯
        $templateProcessor->setValue('political', $politicalOutlook[$data['political_outlook']??0]['value']); // 政治面貌
        $templateProcessor->setValue('nation', !empty($data['nation'])?$nation[$data['nation']]['value']:' '); // 民族
        $templateProcessor->setValue('marital_status', $maritalStatus[$data['marital_status']??0]['value']); // 婚姻状况
        $templateProcessor->setValue('career', $data['career']??' '); // 职业
        $templateProcessor->setValue('interest', $data['interest']??' '); // 兴趣爱好
        $templateProcessor->setValue('address', $data['address']??' '); // 详细住址

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/basic_detail/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取健康情况数据
     * @param $data
     * @return array|false
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getHealthInfo($data): bool|array
    {
        $userArchive = new UserArchiveModel();
        $whereArchive = [
            ['user_id','=',$data['user_id']],
            ['type_id','=',$data['type']],
            ['is_repeal','=',0],
        ];
        $info = $userArchive->where($whereArchive)->field('content,time')->find();
        if(!empty($info['content'])){
            $ret['time'] = $info['time'];
            $content = json_decode($info['content'],true);
            $tempQuestionContent = [];
            foreach($content as $item){
                $tempQuestionContent[$item['quesitionId']] = $item;
            }
            $basicHealthTemplate = new UserArchiveTemplateModel();
            $retName = [
                ['name'=>'basicHealth','pid'=>17,'type_id'=>2], //基本健康情况
                ['name'=>'disabilitySituation','pid'=>42,'type_id'=>2], //残疾情况
                ['name'=>'recentHealth','pid'=>48,'type_id'=>2], //近期健康状态评估
                ['name'=>'healthQuestionnaire','pid'=>61,'type_id'=>2], //健康状况问卷
            ];
            foreach($retName as $item){
                $rets[$item['name']] = $basicHealthTemplate->where([['pid','=',$item['pid']],['type_id','=',$item['type_id']]])->field('id,name')->select()->toArray();
                $ret[$item['name']] = $this->getRet($rets[$item['name']],$tempQuestionContent);
            }
            return $ret;
        }else{
            $this->message = '暂无内容！';
            return false;
        }
    }

    /**
     * 获取用户填写的结果
     * @param $array  //问题集合
     * @param $tempQuestionContent  //用户的问题答案集合
     * @return mixed
     */
    public function getRet($array, $tempQuestionContent): mixed
    {
        /*获取所有答案-开始*/
        $basicAnswerMode = new UserArchiveOptionModel();
        $basicAnswerList = $basicAnswerMode->field('id,template_id,name')->select();
        $basicAnswerListArray = [];
        foreach($basicAnswerList as $item){
            $basicAnswerListArray[$item['id']] = $item->toArray();
        }
        /*获取所有答案-结束*/
        foreach ($array as &$item) {
            $tempId = $item['id'];
            // 检查tempQuestionContent中是否存在tempId键
            if (array_key_exists($tempId, $tempQuestionContent)) {
                // 检查是否存在answerId
                if (!empty($tempQuestionContent[$tempId]['answerId'])) {
                    $item['answer'] = !empty($tempQuestionContent[$tempId]['text']) ?
                        $tempQuestionContent[$tempId]['text'] :
                        $basicAnswerListArray[$tempQuestionContent[$tempId]['answerId']]['name'];
                } else {
                    $item['answer'] = !empty($tempQuestionContent[$tempId]['text']) ?
                        $tempQuestionContent[$tempId]['text'] :
                        $tempQuestionContent[$tempId]['answerId'];
                }
            } else {
                $item['answer'] = ''; // 或者其他默认值，取决于你的需求
            }
        }
        return $array;
    }

    /**
     * 导出健康情况数据
     * @param $data
     * @return string
     */
    public function exportHealthDetail($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/HealthCondition.docx');
        $templateProcessor->setValue('title', '健康情况'); // 档案标题
        $templateProcessor->setValue('end_time', !empty($data['time'])?date('Y年m月d日',$data['time']):'--'); // 档案最后更新时间

        /*基本健康情况-开始*/
        $templateProcessor->setValue('Developmental', $data['basicHealth'][0]['answer']??'--'); // 发育状况
        $templateProcessor->setValue('weight', $data['basicHealth'][1]['answer']??'--'); // 体重
        $templateProcessor->setValue('height', $data['basicHealth'][2]['answer']??'--'); // 身高
        $templateProcessor->setValue('bodyType', $data['basicHealth'][3]['answer']??'--'); // 身型评估
        $templateProcessor->setValue('intelligence', $data['basicHealth'][4]['answer']??'--'); // 智力评估
        $templateProcessor->setValue('hearing', $data['basicHealth'][5]['answer']??'--'); // 听力
        $templateProcessor->setValue('leftEyeVision', $data['basicHealth'][6]['answer']??'--'); // 左眼视力
        $templateProcessor->setValue('rightEyeVision', $data['basicHealth'][7]['answer']??'--'); // 右眼视力
        $templateProcessor->setValue('recognize', $data['basicHealth'][8]['answer']??'--'); // 辨色能力
        $templateProcessor->setValue('language', $data['basicHealth'][9]['answer']??'--'); // 语言能力
        $templateProcessor->setValue('attention', $data['basicHealth'][10]['answer']??'--'); // 注意力
        $templateProcessor->setValue('disease', $data['basicHealth'][11]['answer']??'--'); // 遗传病史
        $templateProcessor->setValue('eatingHabits', $data['basicHealth'][12]['answer']??'--'); // 饮食习惯
        $templateProcessor->setValue('smokingSituation', $data['basicHealth'][13]['answer']??'--'); // 吸烟情况
        $tempSmokingVolume = $data['basicHealth'][14]['answer']??'--';
        $templateProcessor->setValue('smokingVolume', empty($tempSmokingVolume)?$tempSmokingVolume:'日吸烟量:'.$tempSmokingVolume.'支/天'); // 日吸烟量
        $tempSmokerAge = $data['basicHealth'][15]['answer']??'--';
        $templateProcessor->setValue('smokerAge',empty($tempSmokerAge)?$tempSmokerAge:'累计烟龄:'.$tempSmokerAge.'年'); // 累计烟龄
        $tempSmokerTime = $data['basicHealth'][16]['answer']??'--';
        $templateProcessor->setValue('smokerTime', empty($tempSmokerTime)?$tempSmokerTime:'戒烟时长:'.$tempSmokerTime.'年'); // 戒烟时长
        $templateProcessor->setValue('drinkAlcohol', $data['basicHealth'][17]['answer']??'--'); // 饮酒情况
        $templateProcessor->setValue('DrinkingYear', $data['basicHealth'][18]['answer']??'--'); // 戒酒时长
        $templateProcessor->setValue('DrinkingFrequency', $data['basicHealth'][19]['answer']??'--'); // 饮酒频率
        $templateProcessor->setValue('number', $data['basicHealth'][20]['answer']??'--'); // 醉酒次数
        $templateProcessor->setValue('drunkenness', $data['basicHealth'][21]['answer']??'--'); // 平均一次
        $templateProcessor->setValue('DrinkingAge', $data['basicHealth'][22]['answer']??'--'); // 平均一次
        $tempDrinkType = $data['basicHealth'][23]['answer']??'--';
        $templateProcessor->setValue('drinkType', $tempDrinkType); // 饮酒种类
        if(empty($tempDrinkType)){
            $templateProcessor->setValue('drinkContent', $tempDrinkType); // 饮酒种类【其他：内容】
        }else{
            $templateProcessor->setValue('drinkContent', ''); // 饮酒种类【其他：内容】
        }
        /*基本健康情况-结束*/

        /*残疾情况-开始*/
        $templateProcessor->setValue('disability', $data['disabilitySituation'][0]['answer']??'--'); // 是否残疾
        $templateProcessor->setValue('reason', $data['disabilitySituation'][1]['answer']??'--'); // 残疾原因
        $templateProcessor->setValue('type', $data['disabilitySituation'][2]['answer']??'--'); // 残疾分类
        $templateProcessor->setValue('level', $data['disabilitySituation'][3]['answer']??'--'); // 残疾级别
        $templateProcessor->setValue('DisabilityNumber', $data['disabilitySituation'][4]['answer']??'--'); // 残疾证号
        /*残疾情况-结束*/

        /*近期健康状态评估-开始*/
        $templateProcessor->setValue('health', $data['recentHealth'][0]['answer']??'--'); // 健康程度
        $templateProcessor->setValue('DiagnosticResults', $data['recentHealth'][1]['answer']??'--'); // 医院诊断结果
        $templateProcessor->setValue('mainSymptoms', $data['recentHealth'][2]['answer']??'--'); // 主要症状
        $templateProcessor->setValue('AccompaniedSymptoms', $data['recentHealth'][3]['answer']??'--'); // 伴随症状
        $templateProcessor->setValue('takeMedicine', $data['recentHealth'][4]['answer']??'--'); // 是否服药
        $templateProcessor->setValue('DrugName', $data['recentHealth'][5]['answer']??'--'); // 药物名称
        $templateProcessor->setValue('forbidden', $data['recentHealth'][6]['answer']??'--'); // 是否忌口
        $templateProcessor->setValue('fbFoods', $data['recentHealth'][7]['answer']??'--'); // 忌口食物
        $templateProcessor->setValue('fbDrug', $data['recentHealth'][8]['answer']??'--'); // 忌服药物
        $templateProcessor->setValue('aberration', $data['recentHealth'][9]['answer']??'--'); // 异常行为
        $templateProcessor->setValue('preference', $data['recentHealth'][10]['answer']??'--'); // 特殊喜好
        $templateProcessor->setValue('hate', $data['recentHealth'][11]['answer']??'--'); // 特殊厌恶
        /*近期健康状态评估-结束*/

        /*健康状况问卷-开始*/
        $templateProcessor->setValue('questionOne', $data['healthQuestionnaire'][0]['answer']??'--'); // 问题一
        $templateProcessor->setValue('questionTwo', $data['healthQuestionnaire'][1]['answer']??'--'); // 问题2
        $templateProcessor->setValue('questionThree', $data['healthQuestionnaire'][2]['answer']??'--'); // 问题4
        $templateProcessor->setValue('questionFour', $data['healthQuestionnaire'][3]['answer']??'--'); // 问题4
        $templateProcessor->setValue('questionFive', $data['healthQuestionnaire'][4]['answer']??'--'); // 问题5
        $templateProcessor->setValue('questionSix', $data['healthQuestionnaire'][5]['answer']??'--'); // 问题6
        $templateProcessor->setValue('questionSeven', $data['healthQuestionnaire'][6]['answer']??'--'); // 问题7
        $templateProcessor->setValue('questionEight', $data['healthQuestionnaire'][7]['answer']??'--'); // 问题8
        $templateProcessor->setValue('questionNine', $data['healthQuestionnaire'][8]['answer']??'--'); // 问题9
        $templateProcessor->setValue('questionTen', $data['healthQuestionnaire'][9]['answer']??'--'); // 问题10
        $templateProcessor->setValue('questionEleven', $data['healthQuestionnaire'][10]['answer']??'--'); // 问题11
        $templateProcessor->setValue('questionTwelve', $data['healthQuestionnaire'][11]['answer']??'--'); // 问题12
        $templateProcessor->setValue('questionThirteen', $data['healthQuestionnaire'][12]['answer']??'--'); // 问题13
        $templateProcessor->setValue('questionFourteen', $data['healthQuestionnaire'][13]['answer']??'--'); // 问题14
        /*健康状况问卷-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/basic_health/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取教育情况数据
     * @param $data
     * @return array|false
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getEducationInfo($data): bool|array
    {
        $userArchive = new UserArchiveModel();
        $whereArchive = [
            ['user_id','=',$data['user_id']],
            ['type_id','=',$data['type']],
            ['is_repeal','=',0],
        ];
        $info = $userArchive->where($whereArchive)->field('content,time')->find();
        if(!empty($info['content'])){
            $ret['time'] = $info['time'];
            $content = json_decode($info['content'],true);

            $tempQuestionContent = [];
            $otherNum = 0; //其他教育经历的次数
            foreach($content as $item){
                if(!check_array_key('index',$item)){
                    $tempQuestionContent[$item['quesitionId'].'-'.'999999999'] = $item;//第一个
                }else{
                    if($otherNum < $item['index']){
                        $otherNum = $item['index'];
                    }
                    $tempQuestionContent[$item['quesitionId'].'-'.$item['index']] = $item; //其他几个
                }
            }
            $basicHealthTemplate = new UserArchiveTemplateModel();
            $retNames = [
                ['name'=>'basicEducation','pid'=>76,'type_id'=>3], //目前教育情况概况
            ];
            $arrays = [];//其他教育经历
            for ($i=0;$i<=$otherNum;$i++){
                $arrays[$i]['name'] = 'other'.$i;
                $arrays[$i]['pid'] = 195;
                $arrays[$i]['type_id'] = 3;
            }
            $retName = array_merge($retNames,$arrays);
            foreach($retName as $key=>$item){
                $rets[$item['name']] = $basicHealthTemplate->where([['pid','=',$item['pid']],['type_id','=',$item['type_id']]])->field('id,name')->select()->toArray();
                switch ($item['name']){
                    case 'basicEducation':
                        $tempName = '999999999';
                        break;
                    default:
                        $tempName = intval($key-1);
                        break;
                }
                foreach($rets[$item['name']] as &$value){
                    $value['id'] = $value['id'].'-'.$tempName;
                }
                $ret[$item['name']] = $this->getEducationRet($rets[$item['name']],$tempQuestionContent);
            }
            return $ret;
        }else{
            $this->message = '暂无内容！';
            return false;
        }
    }

    /**
     * 获取教育情况用户填的值
     * @param $array
     * @param $tempQuestionContent
     * @return mixed
     */
    public function getEducationRet($array, $tempQuestionContent): mixed
    {
        /*获取所有答案-开始*/
        $basicAnswerMode = new UserArchiveOptionModel();
        $basicAnswerList = $basicAnswerMode->field('id,template_id,name')->select();
        $basicAnswerListArray = [];
        foreach($basicAnswerList as $item){
            $basicAnswerListArray[$item['id']] = $item->toArray();
        }
        /*获取所有答案-结束*/
        foreach ($array as &$item) {
            $tempId = $item['id'];
            // 检查是否存在answerId
            if (!empty($tempQuestionContent[$tempId]['answerId'])) {
                $item['answer'] = $basicAnswerListArray[$tempQuestionContent[$tempId]['answerId']]['name'];
            }else{
                $timestamp = strtotime($tempQuestionContent[$tempId]['text']??'');
                if($timestamp){
                    $item['answer'] = date('Y-m-d', $timestamp);
                }else{
                    $item['answer'] = $tempQuestionContent[$tempId]['text']??'';
                }
            }
        }
        return $array;
    }

    /**
     * 导出教育情况
     * @param $data
     * @return string
     */
    public function exportEducationDetail($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/exportEducationDetail.docx');
        $templateProcessor->setValue('title', '教育情况'); // 档案标题
        $templateProcessor->setValue('end_time',!empty($data['time'])?date('Y年m月d日',$data['time']):'--'); // 档案最后更新时间

        /*目前教育情况概况-开始*/
        $templateProcessor->setValue('qualification', $data['basicEducation'][0]['answer']??'--'); // 学历程度
        $templateProcessor->setValue('enrollment', $data['basicEducation'][1]['answer']??'--'); // 就读状态
        $templateProcessor->setValue('residency', $data['basicEducation'][2]['answer']??'--'); // 是否住校
        $templateProcessor->setValue('startTimes', $data['basicEducation'][3]['answer']??'--'); // 入学时间
        $templateProcessor->setValue('department', $data['basicEducation'][4]['answer']??'--'); // 就读年级
        $templateProcessor->setValue('semester', $data['basicEducation'][5]['answer']??'--'); // 学期
        $templateProcessor->setValue('headTeacher', $data['basicEducation'][6]['answer']??'--'); // 班主任
        $templateProcessor->setValue('phones', $data['basicEducation'][7]['answer']??'--'); // 班主任电话
        $templateProcessor->setValue('phone', $data['basicEducation'][8]['answer']??'--'); // 家长电话
        $templateProcessor->setValue('subsidy', $data['basicEducation'][9]['answer']??'--'); // 两免一补
        $templateProcessor->setValue('placementType', $data['basicEducation'][10]['answer']??'--'); // 安置类型
        $templateProcessor->setValue('remark', $data['basicEducation'][11]['answer']??'--'); // 备注信息
        /*目前教育情况概况-结束*/
        if(isset($data['time'])){
            unset($data['time']);
        }
        if (isset($data['basicEducation'])){
            unset($data['basicEducation']);
        }
        if ($data){
            $tempDate = array_values($data);
            /*其他教育经历-开始*/
            $templateProcessor->cloneBlock('result_block', count($tempDate), true, true);
            foreach($tempDate as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('qualifications#' . $index, $value[0]['answer']??'--');  //学历程度
                $templateProcessor->setValue('graduate#' . $index, $value[1]['answer']??'--');  //是否毕业:
                $templateProcessor->setValue('residencys#' . $index, $value[2]['answer']??'--');  //是否住校:
                $templateProcessor->setValue('startTime#' . $index, $value[3]['answer']??'--'); //入学时间
                $templateProcessor->setValue('endTime#' . $index, $value[4]['answer']??'--'); //结束时间
                $templateProcessor->setValue('isAward#' . $index, $value[5]['answer']??'--'); //是否获奖
                $templateProcessor->setValue('awardSituation#' . $index, $value[6]['answer']??'--'); //获奖情况
                $templateProcessor->setValue('otherRemark#' . $index, $value[7]['answer']??'--'); //其他备注
                $templateProcessor->setValue('blank#' . $index, ' '); //空格
            }
        }
        /*其他教育经历-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/basic_education/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取残障等级信息
     * @param $data
     * @return array|false
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getDisabilityLevelInfo($data): bool|array
    {
        $userArchive = new UserArchiveModel();
        $whereArchive = [
            ['user_id','=',$data['user_id']],
            ['type_id','=',$data['type']],
            ['is_repeal','=',0],
        ];
        $info = $userArchive->where($whereArchive)->field('content,time')->find();
        if(!empty($info['content'])){
            $ret['time'] = $info['time'];
            $content = json_decode($info['content'],true);
            $type = $this->get_type();
            $tempType = [];
            foreach($type as $item){
                $tempType[$item['id']] = $item;
            }
            $level = $this->get_level();
            $tempLevel = [];
            foreach($level as $item){
                $tempLevel[$item['id']] = $item;
            }
            $ret['disability'] = [];
            foreach($content['answerIds']??[] as $key=>$item)
            {
                $ret['disability'][$key]['type'] = empty($item[0])?'':$tempType[$item[0]]['name'];
                $ret['disability'][$key]['level'] = empty($item[1])?'':$tempLevel[$item[1]]['name'];
                $ret['disability'][$key]['remark'] = $item[2];
            }
            return $ret;
        }else{
            $this->message = '暂无内容！';
            return false;
        }
    }

    /**
     * 所有残疾类型
     * @return array[]
     */
    public function get_type(): array
    {
        return [
            ['id'=>1,'name'=>'视力残疾'],
            ['id'=>2,'name'=>'听力残疾'],
            ['id'=>3,'name'=>'语言残疾'],
            ['id'=>4,'name'=>'肢体残疾'],
            ['id'=>5,'name'=>'智力残疾'],
            ['id'=>6,'name'=>'精神残疾'],
            ['id'=>7,'name'=>'多重残疾'],
        ];
    }

    /**
     * 所有残疾等级
     * @return array[]
     */
    public function get_level(): array
    {
        return [
            ['id'=>1,'name'=>'一级残疾'],
            ['id'=>2,'name'=>'二级残疾'],
            ['id'=>3,'name'=>'三级残疾'],
            ['id'=>4,'name'=>'四级残疾'],
            ['id'=>5,'name'=>'五级残疾'],
            ['id'=>6,'name'=>'六级残疾'],
            ['id'=>7,'name'=>'七级残疾'],
            ['id'=>8,'name'=>'八级残疾'],
            ['id'=>9,'name'=>'九级残疾'],
            ['id'=>10,'name'=>'十级残疾'],
        ];
    }

    /**
     * 导出残障等级
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportDisabilityLeve($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/exportDisabilityLeve.docx');
        $templateProcessor->setValue('title', '残障等级'); // 档案标题
        $templateProcessor->setValue('end_time',!empty($data['time']) ? date('Y年m月d日',$data['time']):'--'); // 档案最后更新时间

        $templateProcessor->cloneRow('type', count($data['disability']??[]));
        foreach($data['disability']??[] as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('type#' . $index, $value['type']??'--');
            $templateProcessor->setValue('level#' . $index, $value['level']??'--');
            $templateProcessor->setValue('remark#' . $index, $value['remark']??'--');
        }

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/disability_leve/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取家庭情况
     * @param $data
     * @return array|false
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getFamilySituationInfo($data): bool|array
    {
        $userArchive = new UserArchiveModel();
        $whereArchive = [
            ['user_id','=',$data['user_id']],
            ['type_id','=',$data['type']],
            ['is_repeal','=',0],
        ];
        $info = $userArchive->where($whereArchive)->field('content,time')->find();
        if(!empty($info['content'])){
            $ret['time'] = $info['time'];
            $content = json_decode($info['content'],true);
            $tempQuestionContent = [];
            foreach($content['items'] as $item){
                $tempQuestionContent[$item['quesitionId']] = $item;
            }
            $basicHealthTemplate = new UserArchiveTemplateModel();
            $retName = [
                ['name'=>'familyBackground','pid'=>93,'type_id'=>5], //家庭背景概况
                ['name'=>'familyRelationships','pid'=>114,'type_id'=>5], //家庭关系问卷
                ['name'=>'dailyFamilyLife','pid'=>119,'type_id'=>5], //日常家庭生活情况
            ];
            foreach($retName as $item){
                $rets[$item['name']] = $basicHealthTemplate->where([['pid','=',$item['pid']],['type_id','=',$item['type_id']]])->field('id,name')->select()->toArray();
                $ret[$item['name']] = $this->getRet($rets[$item['name']],$tempQuestionContent);
            }
            $ret['familyMember'] = [];
            $cooperationSituation = $this->get_cooperation_situation();
            $tempCooperationSituation = [];
            foreach($cooperationSituation as $item){
                $tempCooperationSituation[$item['id']] = $item;
            }
            foreach($content['remember']['answerIds']??[] as $key=>$item)
            {
                $ret['familyMember'][$key]['nickname'] = $item[0]; //姓名
                $ret['familyMember'][$key]['age'] = $item[1]; //年龄
                $ret['familyMember'][$key]['kinship'] = $item[2]; //亲属关系
                $ret['familyMember'][$key]['career'] = $item[3]; //职业
                $ret['familyMember'][$key]['phone'] = $item[4]; //联系方式
                $ret['familyMember'][$key]['income'] = $item[5]; //收入
                $ret['familyMember'][$key]['degreeOfEducation'] = $item[6]; //文化程度
                $ret['familyMember'][$key]['healthStatus'] = $item[7]; //健康状况、残疾状况
                $ret['familyMember'][$key]['cooperation'] = empty($item[8])?'':$tempCooperationSituation[$item[8]]['name']; //学校配合情况
            }
            return $ret;
        }else{
            $this->message = '暂无内容！';
            return false;
        }
    }

    /**
     * 获取学校配合情况
     * @return array[]
     */
    public function get_cooperation_situation(): array
    {
        return [
            ['id'=>1,'name'=>'高度配合'],
            ['id'=>2,'name'=>'配合'],
            ['id'=>3,'name'=>'不配合'],
            ['id'=>4,'name'=>'高度不配合'],
        ];
    }

    /**
     * 导出家庭情况
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportFamilySituation($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/FamilySituation.docx');
        $templateProcessor->setValue('title', '家庭情况'); // 档案标题
        $templateProcessor->setValue('end_time', !empty($data['time']) ? date('Y年m月d日',$data['time']) : '--'); // 档案最后更新时间
        /*家庭背景概况-开始*/
        $templateProcessor->setValue('familySituation', $data['familyBackground'][0]['answer']??'--'); // 家庭情况
        $templateProcessor->setValue('familySize', $data['familyBackground'][1]['answer']??'--'); // 家庭人口数
        $templateProcessor->setValue('maritalStatus', $data['familyBackground'][2]['answer']??'--'); // 父母婚姻状况
        $templateProcessor->setValue('familyStrength', $data['familyBackground'][3]['answer']??'--'); // 家庭经济实力
        $templateProcessor->setValue('intelligence', $data['familyBackground'][4]['answer']??'--'); // 有无兄弟姐妹
        $templateProcessor->setValue('homeRanking', $data['familyBackground'][5]['answer']??'--'); // 家中排行
        $templateProcessor->setValue('selfWithParents', $data['familyBackground'][6]['answer']??'--'); // 与父母关系
        $templateProcessor->setValue('selfWithOther', $data['familyBackground'][7]['answer']??'--'); // 是否烈士或优抚对象子女
        $templateProcessor->setValue('martyrsChildren', $data['familyBackground'][8]['answer']??'--'); // 是否烈士或优抚对象子女
        $templateProcessor->setValue('detailedHomeAddress', $data['familyBackground'][9]['answer']??'--'); // 详细家庭住址
        /*家庭背景概况-结束*/

        /*家庭主要成员-开始*/
        $templateProcessor->cloneRow('name', count($data['familyMember']??[]));
        foreach($data['familyMember']??[] as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('name#' . $index, $value['nickname']??'--');  //姓名
            $templateProcessor->setValue('age#' . $index, $value['age']??'--');  //年龄
            $templateProcessor->setValue('kinship#' . $index, $value['kinship']??'--');  //亲属关系
            $templateProcessor->setValue('career#' . $index, $value['career']??'--');  //职业
            $templateProcessor->setValue('phone#' . $index, $value['phone']??'--');  //联系方式
            $templateProcessor->setValue('income#' . $index, $value['income']??'--');  //收入
            $templateProcessor->setValue('degree#' . $index, $value['degreeOfEducation']??'--');  //文化程度
            $templateProcessor->setValue('condition#' . $index, $value['healthStatus']??'--');  //健康状况、残疾状况
            $templateProcessor->setValue('status#' . $index, $value['cooperation']??'--');  //学校配合情况
        }
        /*家庭主要成员-结束*/

        /*家庭关系问卷-开始*/
        $templateProcessor->setValue('questionOne', $data['familyRelationships'][0]['answer']??'--'); // 问题一
        $templateProcessor->setValue('questionTwo', $data['familyRelationships'][1]['answer']??'--'); // 问题二
        $templateProcessor->setValue('questionThree', $data['familyRelationships'][2]['answer']??'--'); // 问题三
        $templateProcessor->setValue('questionFour', $data['familyRelationships'][3]['answer']??'--'); // 问题四
        /*家庭关系问卷-结束*/

        /*日常家庭生活情况-开始*/
        $templateProcessor->setValue('questionOneOne', $data['dailyFamilyLife'][0]['answer']??'--'); // 问题一
        $templateProcessor->setValue('questionOneTwo', $data['dailyFamilyLife'][1]['answer']??'--'); // 问题二
        $templateProcessor->setValue('questionOneThree', $data['dailyFamilyLife'][2]['answer']??'--'); // 问题三
        $templateProcessor->setValue('questionOneFour', $data['dailyFamilyLife'][3]['answer']??'--'); // 问题四
        $templateProcessor->setValue('questionOneFive', $data['dailyFamilyLife'][4]['answer']??'--'); // 问题五
        $templateProcessor->setValue('questionOneSix', $data['dailyFamilyLife'][5]['answer']??'--'); // 问题六
        $templateProcessor->setValue('questionOneSeven', $data['dailyFamilyLife'][6]['answer']??'--'); // 问题七
        $templateProcessor->setValue('questionOneEight', $data['dailyFamilyLife'][7]['answer']??'--'); // 问题八
        /*日常家庭生活情况-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/family_situation/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取家庭访谈数据
     * @param $data
     * @return array|false
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getFamilyInterviewsInfo($data): bool|array
    {
        $userArchive = new UserArchiveModel();
        $whereArchive = [
            ['user_id','=',$data['user_id']],
            ['type_id','=',$data['type']],
            ['is_repeal','=',0],
        ];
        $info = $userArchive->where($whereArchive)->field('content,time')->find();
        if(!empty($info['content'])){
            $ret['time'] = $info['time'];
            $content = json_decode($info['content'],true);
            $tempQuestionContent = [];
            foreach($content as $item){
                $tempQuestionContent[$item['quesitionId']] = $item;
            }
            $basicHealthTemplate = new UserArchiveTemplateModel();
            $retName = [
                ['name'=>'economyReachEducation','pid'=>128,'type_id'=>6], //经济及教育子女情况
                ['name'=>'lifestyle','pid'=>139,'type_id'=>6], //生活习惯与能力
                ['name'=>'livingEnvironment','pid'=>147,'type_id'=>6], //居住环境
            ];
            foreach($retName as $item){
                $rets[$item['name']] = $basicHealthTemplate->where([['pid','=',$item['pid']],['type_id','=',$item['type_id']]])->field('id,name')->select()->toArray();
                $ret[$item['name']] = $this->getRet($rets[$item['name']],$tempQuestionContent);
            }
            return $ret;
        }else{
            $this->message = '暂无内容！';
            return false;
        }
    }

    /**
     * 导出家庭访谈
     * @param $data
     * @return string
     */
    public function exportFamilyInterviews($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/FamilyInterviews.docx');
        $templateProcessor->setValue('title', '家庭访谈'); // 档案标题
        $templateProcessor->setValue('end_time', !empty($data['time']) ? date('Y年m月d日',$data['time']) : '--'); // 档案最后更新时间

        /*经济及教育子女情况-开始*/
        $templateProcessor->setValue('questionOneOne', $data['economyReachEducation'][0]['answer']??'--'); // 问题一
        $templateProcessor->setValue('questionOneTwo', $data['economyReachEducation'][1]['answer']??'--'); // 问题二
        $templateProcessor->setValue('questionOneThree', $data['economyReachEducation'][2]['answer']??'--'); // 问题三
        $templateProcessor->setValue('questionOneFour', $data['economyReachEducation'][3]['answer']??'--'); // 问题四
        $templateProcessor->setValue('questionOneFive', $data['economyReachEducation'][4]['answer']??'--'); // 问题五
        $templateProcessor->setValue('questionOneSix', $data['economyReachEducation'][5]['answer']??'--'); // 问题六
        $templateProcessor->setValue('questionOneSeven', $data['economyReachEducation'][6]['answer']??'--'); // 问题七
        $templateProcessor->setValue('questionOneEight', $data['economyReachEducation'][7]['answer']??'--'); // 问题八
        $templateProcessor->setValue('questionOneNine', $data['economyReachEducation'][8]['answer']??'--'); // 问题九
        $templateProcessor->setValue('questionOneTent', $data['economyReachEducation'][9]['answer']??'--'); // 问题十
        /*经济及教育子女情况-结束*/

        /*生活习惯与能力-开始*/
        $templateProcessor->setValue('dailyEating', $data['lifestyle'][0]['answer']??'--'); // 日常进食
        $templateProcessor->setValue('dressed', $data['lifestyle'][1]['answer']??'--'); // 起床穿衣:
        $templateProcessor->setValue('dailyHygiene', $data['lifestyle'][2]['answer']??'--'); // 生活盥洗:
        $templateProcessor->setValue('goToilet', $data['lifestyle'][3]['answer']??'--'); // 如厕:
        $templateProcessor->setValue('goOut', $data['lifestyle'][4]['answer']??'--'); // 外出:
        $templateProcessor->setValue('organizeItems', $data['lifestyle'][5]['answer']??'--'); // 整理物品:
        $templateProcessor->setValue('remark', $data['lifestyle'][6]['answer']??'--'); // 备注信息:
        /*生活习惯与能力-结束*/

        /*居住环境-开始*/
        $templateProcessor->setValue('questionOne', $data['livingEnvironment'][0]['answer']??'--'); // 问题一
        $templateProcessor->setValue('questionTwo', $data['livingEnvironment'][1]['answer']??'--'); // 问题二
        $templateProcessor->setValue('questionThree', $data['livingEnvironment'][2]['answer']??'--'); // 问题三
        $templateProcessor->setValue('questionFour', $data['livingEnvironment'][3]['answer']??'--'); // 问题四
        $templateProcessor->setValue('questionFive', $data['livingEnvironment'][4]['answer']??'--'); // 问题五
        $templateProcessor->setValue('questionSix', $data['livingEnvironment'][5]['answer']??'--'); // 问题六
        /*居住环境-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/family_interviews/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取精神状态数据
     * @param $data
     * @return array|false
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getMentalStateInfo($data): bool|array
    {
        $userArchive = new UserArchiveModel();
        $whereArchive = [
            ['user_id','=',$data['user_id']],
            ['type_id','=',$data['type']],
            ['is_repeal','=',0],
        ];
        $info = $userArchive->where($whereArchive)->field('content,time')->find();
        if(!empty($info['content'])){
            $ret['time'] = $info['time'];
            $content = json_decode($info['content'],true);
            $tempQuestionContent = [];
            foreach($content as $item){
                $tempQuestionContent[$item['quesitionId']] = $item;
            }
            $basicHealthTemplate = new UserArchiveTemplateModel();
            $retName = [
                ['name'=>'mentalState','pid'=>154,'type_id'=>7], //精神状态概况
                ['name'=>'mentalStateQuestionnaire','pid'=>164,'type_id'=>7], //精神状态概况问卷
            ];
            foreach($retName as $item){
                $rets[$item['name']] = $basicHealthTemplate->where([['pid','=',$item['pid']],['type_id','=',$item['type_id']]])->field('id,name')->select()->toArray();
                $ret[$item['name']] = $this->getRet($rets[$item['name']],$tempQuestionContent);
            }
            return $ret;
        }else{
            $this->message = '暂无内容！';
            return false;
        }
    }

    /**
     * 导出精神状态
     * @param $data
     * @return string
     */
    public function exportMentalState($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/MentalState.docx');
        $templateProcessor->setValue('title', '精神状态'); // 档案标题
        $templateProcessor->setValue('end_time', !empty($data['time'])?date('Y年m月d日',$data['time']):' '); // 档案最后更新时间

        /*精神状态概况-开始*/
        $templateProcessor->setValue('mentalState', $data['mentalState'][0]['answer']??' '); // 精神状态
        $templateProcessor->setValue('hypersomnia', $data['mentalState'][1]['answer']??' '); // 嗜睡:
        $templateProcessor->setValue('attackBehavior', $data['mentalState'][2]['answer']??' '); // 攻击行为:
        $templateProcessor->setValue('hallucination', $data['mentalState'][3]['answer']??' '); // 幻觉:
        $templateProcessor->setValue('pessimistic', $data['mentalState'][4]['answer']??' '); // 容易悲观::
        $templateProcessor->setValue('sleepQuality', $data['mentalState'][5]['answer']??' '); // 睡眠情况:
        $templateProcessor->setValue('forgetful', $data['mentalState'][6]['answer']??' '); // 丢三落四:
        $templateProcessor->setValue('temperament', $data['mentalState'][7]['answer']??' '); // 喜怒无常:
        $templateProcessor->setValue('remark', $data['mentalState'][8]['answer']??' '); // 备注信息:
        /*精神状态概况-结束*/

        /*精神状态概况问卷-开始*/
        $templateProcessor->setValue('questionOneOne', $data['mentalStateQuestionnaire'][0]['answer']??' '); // 问题一
        $templateProcessor->setValue('questionOneTwo', $data['mentalStateQuestionnaire'][1]['answer']??' '); // 问题二
        $templateProcessor->setValue('questionOneThree', $data['mentalStateQuestionnaire'][2]['answer']??' '); // 问题三
        $templateProcessor->setValue('questionOneFour', $data['mentalStateQuestionnaire'][3]['answer']??' '); // 问题四
        $templateProcessor->setValue('questionOneFive', $data['mentalStateQuestionnaire'][4]['answer']??' '); // 问题五
        $templateProcessor->setValue('questionOneSix', $data['mentalStateQuestionnaire'][5]['answer']??' '); // 问题六
        $templateProcessor->setValue('questionOneSeven', $data['mentalStateQuestionnaire'][6]['answer']??' '); // 问题七
        $templateProcessor->setValue('questionOneEight', $data['mentalStateQuestionnaire'][7]['answer']??' '); // 问题八
        $templateProcessor->setValue('questionOneNine', $data['mentalStateQuestionnaire'][8]['answer']??' '); // 问题九
        $templateProcessor->setValue('questionOneTent', $data['mentalStateQuestionnaire'][9]['answer']??' '); // 问题十
        /*精神状态概况问卷-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/mental_state/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 导出全部基本信息
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportAllBasicInfo($data): string
    {
        $sex = $this->getSex($data['basic_info']);
        $tempInfo = new UserService($this->app);
        $studentStatus = $tempInfo->getStudentStatusSelector();//获取所有学籍状态
        $politicalOutlook = $tempInfo->getPoliticalOutlookSelector();//获取所有政治面貌
        $nation = $tempInfo->getNationSelector();//获取所有民族
        $maritalStatus = $tempInfo->getMaritalStatusSelector();//获取所有婚姻状况
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/BasicAll.docx');

        /**基础资料-开始**/
        $templateProcessor->setValue('title', '基础资料'); // 档案标题
        if(!empty($data['basic_info']['update_time'])){
            $update_time = $data['basic_info']['update_time'];
        }else{
            $update_time = $data['basic_info']['time'];
        }
        $templateProcessor->setValue('end_time', date('Y年m月d日',$update_time)); // 档案最后更新时间
        $templateProcessor->setValue('name', $data['basic_info']['name']); // 姓名
        $templateProcessor->setValue('sex', $sex); // 性别
        $templateProcessor->setValue('age', $data['basic_info']['age']); // 年龄
        $templateProcessor->setValue('unit_name', $data['basic_info']['unit_name']); // 所在单位
        $templateProcessor->setValue('department', $data['basic_info']['department_name']); // 所在部门
        $templateProcessor->setValue('number', $data['basic_info']['student_status']); // 编号
        $templateProcessor->setValue('mode_name', $data['basic_info']['mode_name']); // 学制类型
        $templateProcessor->setValue('rules_name', $data['basic_info']['level_rules_name']); // 当前年级
        $templateProcessor->setValue('student', $studentStatus[$data['basic_info']['student_status']]['value']); // 学籍状态
        $templateProcessor->setValue('id_card', $data['basic_info']['id_card']); // 身份证号
        $templateProcessor->setValue('birthday', !empty($data['basic_info']['birthday'])?date('Y-m-d', strtotime($data['basic_info']['birthday'])):$data['basic_info']['birthday']); // 出生日期
        $templateProcessor->setValue('phone', $data['basic_info']['phone']); // 联系方式
        $templateProcessor->setValue('native_place', $data['basic_info']['native_place']); // 籍贯
        $templateProcessor->setValue('political', $politicalOutlook[$data['basic_info']['political_outlook']]['value']); // 政治面貌
        $templateProcessor->setValue('nation', !empty($data['basic_info']['nation'])?$nation[$data['basic_info']['nation']]['value']:' '); // 民族
        $templateProcessor->setValue('marital_status', $maritalStatus[$data['basic_info']['marital_status']]['value']); // 婚姻状况
        $templateProcessor->setValue('career', $data['basic_info']['career']); // 职业
        $templateProcessor->setValue('interest', $data['basic_info']['interest']); // 兴趣爱好
        $templateProcessor->setValue('address', $data['basic_info']['address']); // 详细住址
        /**基础资料-结束**/

        /**健康情况-开始**/
        $templateProcessor->setValue('Health_info_title', '健康情况'); // 档案标题
        if(!empty($data['get_Health_info'])){
            $templateProcessor->setValue('Health_info_end_time', date('Y年m月d日',$data['get_Health_info']['time'])); // 档案最后更新时间

            /*基本健康情况-开始*/
            $templateProcessor->setValue('Developmental', $data['get_Health_info']['basicHealth'][0]['answer']); // 发育状况
            $templateProcessor->setValue('weight', $data['get_Health_info']['basicHealth'][1]['answer']); // 体重
            $templateProcessor->setValue('height', $data['get_Health_info']['basicHealth'][2]['answer']); // 身高
            $templateProcessor->setValue('bodyType', $data['get_Health_info']['basicHealth'][3]['answer']); // 身型评估
            $templateProcessor->setValue('intelligence', $data['get_Health_info']['basicHealth'][4]['answer']); // 智力评估
            $templateProcessor->setValue('hearing', $data['get_Health_info']['basicHealth'][5]['answer']); // 听力
            $templateProcessor->setValue('leftEyeVision', $data['get_Health_info']['basicHealth'][6]['answer']); // 左眼视力
            $templateProcessor->setValue('rightEyeVision', $data['get_Health_info']['basicHealth'][7]['answer']); // 右眼视力
            $templateProcessor->setValue('recognize', $data['get_Health_info']['basicHealth'][8]['answer']); // 辨色能力
            $templateProcessor->setValue('language', $data['get_Health_info']['basicHealth'][9]['answer']); // 语言能力
            $templateProcessor->setValue('attention', $data['get_Health_info']['basicHealth'][10]['answer']); // 注意力
            $templateProcessor->setValue('disease', $data['get_Health_info']['basicHealth'][11]['answer']); // 遗传病史
            $templateProcessor->setValue('eatingHabits', $data['get_Health_info']['basicHealth'][12]['answer']); // 饮食习惯
            $templateProcessor->setValue('smokingSituation', $data['get_Health_info']['basicHealth'][13]['answer']); // 吸烟情况
            $tempSmokingVolume = $data['get_Health_info']['basicHealth'][14]['answer'];
            $templateProcessor->setValue('smokingVolume', empty($tempSmokingVolume)?$tempSmokingVolume:'日吸烟量:'.$tempSmokingVolume.'支/天'); // 日吸烟量
            $tempSmokerAge = $data['get_Health_info']['basicHealth'][15]['answer'];
            $templateProcessor->setValue('smokerAge',empty($tempSmokerAge)?$tempSmokerAge:'累计烟龄:'.$tempSmokerAge.'年'); // 累计烟龄
            $tempSmokerTime = $data['get_Health_info']['basicHealth'][16]['answer'];
            $templateProcessor->setValue('smokerTime', empty($tempSmokerTime)?$tempSmokerTime:'戒烟时长:'.$tempSmokerTime.'年'); // 戒烟时长
            $templateProcessor->setValue('drinkAlcohol', $data['get_Health_info']['basicHealth'][17]['answer']); // 饮酒情况
            $templateProcessor->setValue('DrinkingYear', $data['get_Health_info']['basicHealth'][18]['answer']); // 戒酒时长
            $templateProcessor->setValue('DrinkingFrequency', $data['get_Health_info']['basicHealth'][19]['answer']); // 饮酒频率
            $templateProcessor->setValue('number', $data['get_Health_info']['basicHealth'][20]['answer']); // 醉酒次数
            $templateProcessor->setValue('drunkenness', $data['get_Health_info']['basicHealth'][21]['answer']); // 平均一次
            $templateProcessor->setValue('DrinkingAge', $data['get_Health_info']['basicHealth'][22]['answer']); // 平均一次
            $tempDrinkType = $data['get_Health_info']['basicHealth'][23]['answer'];
            $templateProcessor->setValue('drinkType', $tempDrinkType); // 饮酒种类
            if(empty($tempDrinkType)){
                $templateProcessor->setValue('drinkContent', $tempDrinkType); // 饮酒种类【其他：内容】
            }else{
                $templateProcessor->setValue('drinkContent', ' '); // 饮酒种类【其他：内容】
            }
        }else{
            $templateProcessor->setValue('Health_info_end_time', 0); // 档案最后更新时间

            /*基本健康情况-开始*/
            $templateProcessor->setValue('Developmental', ' '); // 发育状况
            $templateProcessor->setValue('weight', ' '); // 体重
            $templateProcessor->setValue('height', ' '); // 身高
            $templateProcessor->setValue('bodyType', ' '); // 身型评估
            $templateProcessor->setValue('intelligence', ' '); // 智力评估
            $templateProcessor->setValue('hearing', ' '); // 听力
            $templateProcessor->setValue('leftEyeVision', ' '); // 左眼视力
            $templateProcessor->setValue('rightEyeVision', ' '); // 右眼视力
            $templateProcessor->setValue('recognize', ' '); // 辨色能力
            $templateProcessor->setValue('language', ' '); // 语言能力
            $templateProcessor->setValue('attention', ' '); // 注意力
            $templateProcessor->setValue('disease', ' '); // 遗传病史
            $templateProcessor->setValue('eatingHabits', ' '); // 饮食习惯
            $templateProcessor->setValue('smokingSituation', ' '); // 吸烟情况
            $templateProcessor->setValue('smokingVolume', ' '); // 日吸烟量
            $templateProcessor->setValue('smokerAge',' '); // 累计烟龄
            $templateProcessor->setValue('smokerTime', ' '); // 戒烟时长
            $templateProcessor->setValue('drinkAlcohol', ' '); // 饮酒情况
            $templateProcessor->setValue('DrinkingYear', ' '); // 戒酒时长
            $templateProcessor->setValue('DrinkingFrequency', ' '); // 饮酒频率
            $templateProcessor->setValue('number', ' '); // 醉酒次数
            $templateProcessor->setValue('drunkenness', ' '); // 平均一次
            $templateProcessor->setValue('DrinkingAge', ' '); // 平均一次
            $templateProcessor->setValue('drinkType', ' '); // 饮酒种类
            $templateProcessor->setValue('drinkContent', ' '); // 饮酒种类【其他：内容】
        }

        /*基本健康情况-结束*/

        /*残疾情况-开始*/
        if(!empty($data['get_Health_info'])){
            $templateProcessor->setValue('disability', $data['get_Health_info']['disabilitySituation'][0]['answer']); // 是否残疾
            $templateProcessor->setValue('reason', $data['get_Health_info']['disabilitySituation'][1]['answer']); // 残疾原因
            $templateProcessor->setValue('type', $data['get_Health_info']['disabilitySituation'][2]['answer']); // 残疾分类
            $templateProcessor->setValue('level', $data['get_Health_info']['disabilitySituation'][3]['answer']); // 残疾级别
            $templateProcessor->setValue('DisabilityNumber', $data['get_Health_info']['disabilitySituation'][4]['answer']); // 残疾证号
        }else{
            $templateProcessor->setValue('disability', ' '); // 是否残疾
            $templateProcessor->setValue('reason', ' '); // 残疾原因
            $templateProcessor->setValue('type', ' '); // 残疾分类
            $templateProcessor->setValue('level', ' '); // 残疾级别
            $templateProcessor->setValue('DisabilityNumber', ' '); // 残疾证号
        }
        /*残疾情况-结束*/

        /*近期健康状态评估-开始*/
        if(!empty($data['get_Health_info'])){
            $templateProcessor->setValue('health', $data['get_Health_info']['recentHealth'][0]['answer']); // 健康程度
            $templateProcessor->setValue('DiagnosticResults', $data['get_Health_info']['recentHealth'][1]['answer']); // 医院诊断结果
            $templateProcessor->setValue('mainSymptoms', $data['get_Health_info']['recentHealth'][2]['answer']); // 主要症状
            $templateProcessor->setValue('AccompaniedSymptoms', $data['get_Health_info']['recentHealth'][3]['answer']); // 伴随症状
            $templateProcessor->setValue('takeMedicine', $data['get_Health_info']['recentHealth'][4]['answer']); // 是否服药
            $templateProcessor->setValue('DrugName', $data['get_Health_info']['recentHealth'][5]['answer']); // 药物名称
            $templateProcessor->setValue('forbidden', $data['get_Health_info']['recentHealth'][6]['answer']); // 是否忌口
            $templateProcessor->setValue('fbFoods', $data['get_Health_info']['recentHealth'][7]['answer']); // 忌口食物
            $templateProcessor->setValue('fbDrug', $data['get_Health_info']['recentHealth'][8]['answer']); // 忌服药物
            $templateProcessor->setValue('aberration', $data['get_Health_info']['recentHealth'][9]['answer']); // 异常行为
            $templateProcessor->setValue('preference', $data['get_Health_info']['recentHealth'][10]['answer']); // 特殊喜好
            $templateProcessor->setValue('hate', $data['get_Health_info']['recentHealth'][11]['answer']); // 特殊厌恶
        }else{
            $templateProcessor->setValue('health', ' '); // 健康程度
            $templateProcessor->setValue('DiagnosticResults', ' '); // 医院诊断结果
            $templateProcessor->setValue('mainSymptoms', ' '); // 主要症状
            $templateProcessor->setValue('AccompaniedSymptoms', ' '); // 伴随症状
            $templateProcessor->setValue('takeMedicine', ' '); // 是否服药
            $templateProcessor->setValue('DrugName', ' '); // 药物名称
            $templateProcessor->setValue('forbidden', ' '); // 是否忌口
            $templateProcessor->setValue('fbFoods', ' '); // 忌口食物
            $templateProcessor->setValue('fbDrug', ' '); // 忌服药物
            $templateProcessor->setValue('aberration', ' '); // 异常行为
            $templateProcessor->setValue('preference', ' '); // 特殊喜好
            $templateProcessor->setValue('hate', ' '); // 特殊厌恶
        }
        /*近期健康状态评估-结束*/

        /*健康状况问卷-开始*/
        if(!empty($data['get_Health_info'])){
            $templateProcessor->setValue('questionOne', $data['get_Health_info']['healthQuestionnaire'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionTwo', $data['get_Health_info']['healthQuestionnaire'][1]['answer']); // 问题2
            $templateProcessor->setValue('questionThree', $data['get_Health_info']['healthQuestionnaire'][2]['answer']); // 问题4
            $templateProcessor->setValue('questionFour', $data['get_Health_info']['healthQuestionnaire'][3]['answer']); // 问题4
            $templateProcessor->setValue('questionFive', $data['get_Health_info']['healthQuestionnaire'][4]['answer']); // 问题5
            $templateProcessor->setValue('questionSix', $data['get_Health_info']['healthQuestionnaire'][5]['answer']); // 问题6
            $templateProcessor->setValue('questionSeven', $data['get_Health_info']['healthQuestionnaire'][6]['answer']); // 问题7
            $templateProcessor->setValue('questionEight', $data['get_Health_info']['healthQuestionnaire'][7]['answer']); // 问题8
            $templateProcessor->setValue('questionNine', $data['get_Health_info']['healthQuestionnaire'][8]['answer']); // 问题9
            $templateProcessor->setValue('questionTen', $data['get_Health_info']['healthQuestionnaire'][9]['answer']); // 问题10
            $templateProcessor->setValue('questionEleven', $data['get_Health_info']['healthQuestionnaire'][10]['answer']); // 问题11
            $templateProcessor->setValue('questionTwelve', $data['get_Health_info']['healthQuestionnaire'][11]['answer']); // 问题12
            $templateProcessor->setValue('questionThirteen', $data['get_Health_info']['healthQuestionnaire'][12]['answer']); // 问题13
            $templateProcessor->setValue('questionFourteen', $data['get_Health_info']['healthQuestionnaire'][13]['answer']); // 问题14
        }else{
            $templateProcessor->setValue('questionOne', ' '); // 问题一
            $templateProcessor->setValue('questionTwo', ' '); // 问题2
            $templateProcessor->setValue('questionThree', ' '); // 问题4
            $templateProcessor->setValue('questionFour', ' '); // 问题4
            $templateProcessor->setValue('questionFive', ' '); // 问题5
            $templateProcessor->setValue('questionSix', ' '); // 问题6
            $templateProcessor->setValue('questionSeven', ' '); // 问题7
            $templateProcessor->setValue('questionEight', ' '); // 问题8
            $templateProcessor->setValue('questionNine', ' '); // 问题9
            $templateProcessor->setValue('questionTen', ' '); // 问题10
            $templateProcessor->setValue('questionEleven', ' '); // 问题11
            $templateProcessor->setValue('questionTwelve', ' '); // 问题12
            $templateProcessor->setValue('questionThirteen', ' '); // 问题13
            $templateProcessor->setValue('questionFourteen', ' '); // 问题14
        }
        /*健康状况问卷-结束*/
        /**健康情况-结束**/

        /**教育情况-结束**/
        $templateProcessor->setValue('education_info_title', '教育情况'); // 档案标题
        if(!empty($data['get_education_info'])){
            $templateProcessor->setValue('education_info_end_time', date('Y年m月d日',$data['get_education_info']['time'])); // 档案最后更新时间
            /*目前教育情况概况-开始*/
            $templateProcessor->setValue('qualification', $data['get_education_info']['basicEducation'][0]['answer']); // 学历程度
            $templateProcessor->setValue('enrollment', $data['get_education_info']['basicEducation'][1]['answer']); // 就读状态
            $templateProcessor->setValue('residency', $data['get_education_info']['basicEducation'][2]['answer']); // 是否住校
            $templateProcessor->setValue('startTimes', $data['get_education_info']['basicEducation'][3]['answer']); // 入学时间
            $templateProcessor->setValue('Edepartment', $data['get_education_info']['basicEducation'][4]['answer']); // 就读年级
            $templateProcessor->setValue('semester', $data['get_education_info']['basicEducation'][5]['answer']); // 学期
            $templateProcessor->setValue('headTeacher', $data['get_education_info']['basicEducation'][6]['answer']); // 班主任
            $templateProcessor->setValue('phones', $data['get_education_info']['basicEducation'][7]['answer']); // 班主任电话
            $templateProcessor->setValue('phonep', $data['get_education_info']['basicEducation'][8]['answer']); // 家长电话
            $templateProcessor->setValue('subsidy', $data['get_education_info']['basicEducation'][9]['answer']); // 两免一补
            $templateProcessor->setValue('placementType', $data['get_education_info']['basicEducation'][10]['answer']); // 安置类型
            $templateProcessor->setValue('remark', $data['get_education_info']['basicEducation'][11]['answer']); // 备注信息
        }else{
            $templateProcessor->setValue('education_info_end_time', 0); // 档案最后更新时间
            /*目前教育情况概况-开始*/
            $templateProcessor->setValue('qualification', ' '); // 学历程度
            $templateProcessor->setValue('enrollment', ' '); // 就读状态
            $templateProcessor->setValue('residency', ' '); // 是否住校
            $templateProcessor->setValue('startTimes', ' '); // 入学时间
            $templateProcessor->setValue('Edepartment', ' '); // 就读年级
            $templateProcessor->setValue('semester', ' '); // 学期
            $templateProcessor->setValue('headTeacher', ' '); // 班主任
            $templateProcessor->setValue('phones', ' '); // 班主任电话
            $templateProcessor->setValue('phonep', ' '); // 家长电话
            $templateProcessor->setValue('subsidy', ' '); // 两免一补
            $templateProcessor->setValue('placementType', ' '); // 安置类型
            $templateProcessor->setValue('remark', ' '); // 备注信息
        }
        /*目前教育情况概况-结束*/

        if(!empty($data['get_education_info'])){
            unset($data['get_education_info']['time']);
            unset($data['get_education_info']['basicEducation']);
            $tempDate = array_values($data['get_education_info']);
            /*其他教育经历-开始*/
            $templateProcessor->cloneBlock('result_block', count($tempDate), true, true);
            foreach($tempDate as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('qualifications#' . $index, $value[0]['answer']);  //学历程度
                $templateProcessor->setValue('graduate#' . $index, $value[1]['answer']);  //是否毕业:
                $templateProcessor->setValue('residencys#' . $index, $value[2]['answer']);  //是否住校:
                $templateProcessor->setValue('startTime#' . $index, $value[3]['answer']); //入学时间
                $templateProcessor->setValue('endTime#' . $index, $value[4]['answer']); //结束时间
                $templateProcessor->setValue('isAward#' . $index, $value[5]['answer']); //是否获奖
                $templateProcessor->setValue('awardSituation#' . $index, $value[6]['answer']); //获奖情况
                $templateProcessor->setValue('otherRemark#' . $index, $value[7]['answer']); //其他备注
                $templateProcessor->setValue('blank#' . $index, ' '); //空格
            }
            /*其他教育经历-结束*/
        }else{
            /*其他教育经历-开始*/
            $templateProcessor->cloneBlock('result_block', 1, true, true);
            $templateProcessor->setValue('qualifications#1' , ' ');  //学历程度
            $templateProcessor->setValue('graduate#1' , ' ');  //是否毕业:
            $templateProcessor->setValue('residencys#1' , ' ');  //是否住校:
            $templateProcessor->setValue('startTime#1' , ' '); //入学时间
            $templateProcessor->setValue('endTime#1' , ' '); //结束时间
            $templateProcessor->setValue('isAward#1' , ' '); //是否获奖
            $templateProcessor->setValue('awardSituation#1' , ' '); //获奖情况
            $templateProcessor->setValue('otherRemark#1' , ' '); //其他备注
            $templateProcessor->setValue('blank#1' , ' '); //空格
            /*其他教育经历-结束*/

        }

        /**教育情况-结束**/

        /**残障等级-结束**/
        $templateProcessor->setValue('disability_leve_title', '残障等级'); // 档案标题
        if(!empty($data['get_disability_leve_info'])){
            $templateProcessor->setValue('disability_leve_end_time', date('Y年m月d日',$data['get_disability_leve_info']['time'])); // 档案最后更新时间

            $templateProcessor->cloneRow('dType', count($data['get_disability_leve_info']['disability']));
            foreach($data['get_disability_leve_info']['disability'] as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('dType#' . $index, $value['type']??' ');
                $templateProcessor->setValue('dLevel#' . $index, $value['level']??' ');
                $templateProcessor->setValue('dRemark#' . $index, $value['remark']??' ');
            }
        }else{
            $templateProcessor->setValue('disability_leve_end_time', 0); // 档案最后更新时间
            $templateProcessor->setValue('dType', ' ');
            $templateProcessor->setValue('dLevel', ' ');
            $templateProcessor->setValue('dRemark', ' ');
        }

        /**残障等级-结束**/

        /**家庭情况-开始**/
        $templateProcessor->setValue('family_situation_title', '家庭情况'); // 档案标题
        if(!empty($data['get_family_situation_info'])){
            $templateProcessor->setValue('family_situation_end_time', date('Y年m月d日',$data['get_family_situation_info']['time'])); // 档案最后更新时间
            /*家庭背景概况-开始*/
            $templateProcessor->setValue('familySituation', $data['get_family_situation_info']['familyBackground'][0]['answer']); // 家庭情况
            $templateProcessor->setValue('familySize', $data['get_family_situation_info']['familyBackground'][1]['answer']); // 家庭人口数
            $templateProcessor->setValue('maritalStatus', $data['get_family_situation_info']['familyBackground'][2]['answer']); // 父母婚姻状况
            $templateProcessor->setValue('familyStrength', $data['get_family_situation_info']['familyBackground'][3]['answer']); // 家庭经济实力
            $templateProcessor->setValue('intelligence', $data['get_family_situation_info']['familyBackground'][4]['answer']); // 有无兄弟姐妹
            $templateProcessor->setValue('homeRanking', $data['get_family_situation_info']['familyBackground'][5]['answer']); // 家中排行
            $templateProcessor->setValue('selfWithParents', $data['get_family_situation_info']['familyBackground'][6]['answer']); // 与父母关系
            $templateProcessor->setValue('selfWithOther', $data['get_family_situation_info']['familyBackground'][7]['answer']); // 与其他成员关系
            $templateProcessor->setValue('martyrsChildren', $data['get_family_situation_info']['familyBackground'][8]['answer']); // 是否烈士或优抚对象子女
            $templateProcessor->setValue('detailedHomeAddress', $data['get_family_situation_info']['familyBackground'][9]['answer']); // 详细家庭住址
        }else{
            $templateProcessor->setValue('family_situation_end_time', 0); // 档案最后更新时间
            /*家庭背景概况-开始*/
            $templateProcessor->setValue('familySituation', ' '); // 家庭情况
            $templateProcessor->setValue('familySize', ' '); // 家庭人口数
            $templateProcessor->setValue('maritalStatus', ' '); // 父母婚姻状况
            $templateProcessor->setValue('familyStrength', ' '); // 家庭经济实力
            $templateProcessor->setValue('intelligence', ' '); // 有无兄弟姐妹
            $templateProcessor->setValue('homeRanking', ' '); // 家中排行
            $templateProcessor->setValue('selfWithParents', ' '); // 与父母关系
            $templateProcessor->setValue('selfWithOther', ' '); // 与其他成员关系
            $templateProcessor->setValue('martyrsChildren', ' '); // 是否烈士或优抚对象子女
            $templateProcessor->setValue('detailedHomeAddress', ' '); // 详细家庭住址
        }

        /*家庭背景概况-结束*/

        /*家庭主要成员-开始*/
        if(!empty($data['get_family_situation_info'])){
            $templateProcessor->cloneRow('nameF', count($data['get_family_situation_info']['familyMember']));
            foreach($data['get_family_situation_info']['familyMember'] as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('nameF#' . $index, $value['nickname']??' ');  //姓名
                $templateProcessor->setValue('ageF#' . $index, $value['age']??' ');  //年龄
                $templateProcessor->setValue('kinshipF#' . $index, $value['kinship']??' ');  //亲属关系
                $templateProcessor->setValue('careerF#' . $index, $value['career']??' ');  //职业
                $templateProcessor->setValue('phoneF#' . $index, $value['phone']??' ');  //联系方式
                $templateProcessor->setValue('incomeF#' . $index, $value['income']??' ');  //收入
                $templateProcessor->setValue('degreeF#' . $index, $value['degreeOfEducation']??' ');  //文化程度
                $templateProcessor->setValue('conditionF#' . $index, $value['healthStatus']??' ');  //健康状况、残疾状况
                $templateProcessor->setValue('statusF#' . $index, $value['cooperation']??' ');  //学校配合情况
            }
        }else{
            $templateProcessor->setValue('nameF' , ' ');  //姓名
            $templateProcessor->setValue('ageF' , ' ');  //年龄
            $templateProcessor->setValue('kinshipF' , ' ');  //亲属关系
            $templateProcessor->setValue('careerF' , ' ');  //职业
            $templateProcessor->setValue('phoneF' , ' ');  //联系方式
            $templateProcessor->setValue('incomeF' , ' ');  //收入
            $templateProcessor->setValue('degreeF' , ' ');  //文化程度
            $templateProcessor->setValue('conditionF' , ' ');  //健康状况、残疾状况
            $templateProcessor->setValue('statusF' , ' ');  //学校配合情况
        }
        /*家庭主要成员-结束*/

        /*家庭关系问卷-开始*/
        if(!empty($data['get_family_situation_info'])){
            $templateProcessor->setValue('questionOneFs', $data['get_family_situation_info']['familyRelationships'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionTwoFs', $data['get_family_situation_info']['familyRelationships'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionThreeFs', $data['get_family_situation_info']['familyRelationships'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionFourFs', $data['get_family_situation_info']['familyRelationships'][3]['answer']); // 问题四
        }else{
            $templateProcessor->setValue('questionOneFs', ' '); // 问题一
            $templateProcessor->setValue('questionTwoFs', ' '); // 问题二
            $templateProcessor->setValue('questionThreeFs', ' '); // 问题三
            $templateProcessor->setValue('questionFourFs', ' '); // 问题四
        }

        /*家庭关系问卷-结束*/

        /*日常家庭生活情况-开始*/
        if(!empty($data['get_family_situation_info'])){
            $templateProcessor->setValue('questionOneOneFs', $data['get_family_situation_info']['dailyFamilyLife'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionOneTwoFs', $data['get_family_situation_info']['dailyFamilyLife'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionOneThreeFs', $data['get_family_situation_info']['dailyFamilyLife'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionOneFourFs', $data['get_family_situation_info']['dailyFamilyLife'][3]['answer']); // 问题四
            $templateProcessor->setValue('questionOneFiveFs', $data['get_family_situation_info']['dailyFamilyLife'][4]['answer']); // 问题五
            $templateProcessor->setValue('questionOneSixFs', $data['get_family_situation_info']['dailyFamilyLife'][5]['answer']); // 问题六
            $templateProcessor->setValue('questionOneSevenFs', $data['get_family_situation_info']['dailyFamilyLife'][6]['answer']); // 问题七
            $templateProcessor->setValue('questionOneEightFs', $data['get_family_situation_info']['dailyFamilyLife'][7]['answer']); // 问题八
        }else{
            $templateProcessor->setValue('questionOneOneFs', ' '); // 问题一
            $templateProcessor->setValue('questionOneTwoFs', ' '); // 问题二
            $templateProcessor->setValue('questionOneThreeFs', ' '); // 问题三
            $templateProcessor->setValue('questionOneFourFs', ' '); // 问题四
            $templateProcessor->setValue('questionOneFiveFs', ' '); // 问题五
            $templateProcessor->setValue('questionOneSixFs', ' '); // 问题六
            $templateProcessor->setValue('questionOneSevenFs', ' '); // 问题七
            $templateProcessor->setValue('questionOneEightFs', ' '); // 问题八
        }

        /*日常家庭生活情况-结束*/
        /**家庭情况-结束**/

        /**家庭访谈-开始**/
        $templateProcessor->setValue('family_interviews_title', '家庭访谈'); // 档案标题
        if(!empty($data['get_family_interviews_info'])){
            $templateProcessor->setValue('family_interviews_end_time', date('Y年m月d日',$data['get_family_interviews_info']['time'])); // 档案最后更新时间

            /*经济及教育子女情况-开始*/
            $templateProcessor->setValue('questionOneOneI', $data['get_family_interviews_info']['economyReachEducation'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionOneTwoI', $data['get_family_interviews_info']['economyReachEducation'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionOneThreeI', $data['get_family_interviews_info']['economyReachEducation'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionOneFourI', $data['get_family_interviews_info']['economyReachEducation'][3]['answer']); // 问题四
            $templateProcessor->setValue('questionOneFiveI', $data['get_family_interviews_info']['economyReachEducation'][4]['answer']); // 问题五
            $templateProcessor->setValue('questionOneSixI', $data['get_family_interviews_info']['economyReachEducation'][5]['answer']); // 问题六
            $templateProcessor->setValue('questionOneSevenI', $data['get_family_interviews_info']['economyReachEducation'][6]['answer']); // 问题七
            $templateProcessor->setValue('questionOneEightI', $data['get_family_interviews_info']['economyReachEducation'][7]['answer']); // 问题八
            $templateProcessor->setValue('questionOneNineI', $data['get_family_interviews_info']['economyReachEducation'][8]['answer']); // 问题九
            $templateProcessor->setValue('questionOneTentI', $data['get_family_interviews_info']['economyReachEducation'][9]['answer']); // 问题十
        }else{
            $templateProcessor->setValue('family_interviews_end_time', 0); // 档案最后更新时间

            /*经济及教育子女情况-开始*/
            $templateProcessor->setValue('questionOneOneI', ' '); // 问题一
            $templateProcessor->setValue('questionOneTwoI', ' '); // 问题二
            $templateProcessor->setValue('questionOneThreeI', ' '); // 问题三
            $templateProcessor->setValue('questionOneFourI', ' '); // 问题四
            $templateProcessor->setValue('questionOneFiveI', ' '); // 问题五
            $templateProcessor->setValue('questionOneSixI', ' '); // 问题六
            $templateProcessor->setValue('questionOneSevenI', ' '); // 问题七
            $templateProcessor->setValue('questionOneEightI', ' '); // 问题八
            $templateProcessor->setValue('questionOneNineI', ' '); // 问题九
            $templateProcessor->setValue('questionOneTentI', ' '); // 问题十
        }
        /*经济及教育子女情况-结束*/

        /*生活习惯与能力-开始*/
        if(!empty($data['get_family_interviews_info'])){
            $templateProcessor->setValue('dailyEating', $data['get_family_interviews_info']['lifestyle'][0]['answer']); // 日常进食
            $templateProcessor->setValue('dressed', $data['get_family_interviews_info']['lifestyle'][1]['answer']); // 起床穿衣:
            $templateProcessor->setValue('dailyHygiene', $data['get_family_interviews_info']['lifestyle'][2]['answer']); // 生活盥洗:
            $templateProcessor->setValue('goToilet', $data['get_family_interviews_info']['lifestyle'][3]['answer']); // 如厕:
            $templateProcessor->setValue('goOut', $data['get_family_interviews_info']['lifestyle'][4]['answer']); // 外出:
            $templateProcessor->setValue('organizeItems', $data['get_family_interviews_info']['lifestyle'][5]['answer']); // 整理物品:
            $templateProcessor->setValue('remarkI', $data['get_family_interviews_info']['lifestyle'][6]['answer']); // 备注信息:
        }else{
            $templateProcessor->setValue('dailyEating', ' '); // 日常进食
            $templateProcessor->setValue('dressed', ' '); // 起床穿衣:
            $templateProcessor->setValue('dailyHygiene', ' '); // 生活盥洗:
            $templateProcessor->setValue('goToilet', ' '); // 如厕:
            $templateProcessor->setValue('goOut', ' '); // 外出:
            $templateProcessor->setValue('organizeItems', ' '); // 整理物品:
            $templateProcessor->setValue('remarkI', ' '); // 备注信息:
        }

        /*生活习惯与能力-结束*/

        /*居住环境-开始*/
        if(!empty($data['get_family_interviews_info'])){
            $templateProcessor->setValue('questionOneI', $data['get_family_interviews_info']['livingEnvironment'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionTwoI', $data['get_family_interviews_info']['livingEnvironment'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionThreeI', $data['get_family_interviews_info']['livingEnvironment'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionFourI', $data['get_family_interviews_info']['livingEnvironment'][3]['answer']); // 问题四
            $templateProcessor->setValue('questionFiveI', $data['get_family_interviews_info']['livingEnvironment'][4]['answer']); // 问题五
            $templateProcessor->setValue('questionSixI', $data['get_family_interviews_info']['livingEnvironment'][5]['answer']); // 问题六
        }else{
            $templateProcessor->setValue('questionOneI', ' '); // 问题一
            $templateProcessor->setValue('questionTwoI', ' '); // 问题二
            $templateProcessor->setValue('questionThreeI', ' '); // 问题三
            $templateProcessor->setValue('questionFourI', ' '); // 问题四
            $templateProcessor->setValue('questionFiveI', ' '); // 问题五
            $templateProcessor->setValue('questionSixI', ' '); // 问题六
        }
        /*居住环境-结束*/
        /**家庭访谈-结束**/

        /**精神状态-开始**/
        $templateProcessor->setValue('mental_state_title', '精神状态'); // 档案标题
        if(!empty($data['get_mental_state_info'])){
            $templateProcessor->setValue('mental_state_end_time', date('Y年m月d日',$data['get_mental_state_info']['time'])); // 档案最后更新时间

            /*精神状态概况-开始*/
            $templateProcessor->setValue('mentalState', $data['get_mental_state_info']['mentalState'][0]['answer']); // 精神状态
            $templateProcessor->setValue('hypersomnia', $data['get_mental_state_info']['mentalState'][1]['answer']); // 嗜睡:
            $templateProcessor->setValue('attackBehavior', $data['get_mental_state_info']['mentalState'][2]['answer']); // 攻击行为:
            $templateProcessor->setValue('hallucination', $data['get_mental_state_info']['mentalState'][3]['answer']); // 幻觉:
            $templateProcessor->setValue('pessimistic', $data['get_mental_state_info']['mentalState'][4]['answer']); // 容易悲观::
            $templateProcessor->setValue('sleepQuality', $data['get_mental_state_info']['mentalState'][5]['answer']); // 睡眠情况:
            $templateProcessor->setValue('forgetful', $data['get_mental_state_info']['mentalState'][6]['answer']); // 丢三落四:
            $templateProcessor->setValue('temperament', $data['get_mental_state_info']['mentalState'][7]['answer']); // 喜怒无常:
            $templateProcessor->setValue('remarkMs', $data['get_mental_state_info']['mentalState'][8]['answer']); // 备注信息:
        }else{
            $templateProcessor->setValue('mental_state_end_time', 0); // 档案最后更新时间

            /*精神状态概况-开始*/
            $templateProcessor->setValue('mentalState', ' '); // 精神状态
            $templateProcessor->setValue('hypersomnia', ' '); // 嗜睡:
            $templateProcessor->setValue('attackBehavior', ' '); // 攻击行为:
            $templateProcessor->setValue('hallucination', ' '); // 幻觉:
            $templateProcessor->setValue('pessimistic', ' '); // 容易悲观::
            $templateProcessor->setValue('sleepQuality', ' '); // 睡眠情况:
            $templateProcessor->setValue('forgetful', ' '); // 丢三落四:
            $templateProcessor->setValue('temperament', ' '); // 喜怒无常:
            $templateProcessor->setValue('remarkMs', ' '); // 备注信息:
        }
        /*精神状态概况-结束*/

        /*精神状态概况问卷-开始*/
        if(!empty($data['get_mental_state_info'])){
            $templateProcessor->setValue('questionOneOneMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][0]['answer']); // 问题一
            $templateProcessor->setValue('questionOneTwoMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][1]['answer']); // 问题二
            $templateProcessor->setValue('questionOneThreeMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][2]['answer']); // 问题三
            $templateProcessor->setValue('questionOneFourMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][3]['answer']); // 问题四
            $templateProcessor->setValue('questionOneFiveMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][4]['answer']); // 问题五
            $templateProcessor->setValue('questionOneSixMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][5]['answer']); // 问题六
            $templateProcessor->setValue('questionOneSevenMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][6]['answer']); // 问题七
            $templateProcessor->setValue('questionOneEightMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][7]['answer']); // 问题八
            $templateProcessor->setValue('questionOneNineMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][8]['answer']); // 问题九
            $templateProcessor->setValue('questionOneTentMs', $data['get_mental_state_info']['mentalStateQuestionnaire'][9]['answer']); // 问题十
            /*精神状态概况问卷-结束*/
        }else{
            $templateProcessor->setValue('questionOneOneMs', ' '); // 问题一
            $templateProcessor->setValue('questionOneTwoMs', ' '); // 问题二
            $templateProcessor->setValue('questionOneThreeMs', ' '); // 问题三
            $templateProcessor->setValue('questionOneFourMs', ' '); // 问题四
            $templateProcessor->setValue('questionOneFiveMs', ' '); // 问题五
            $templateProcessor->setValue('questionOneSixMs', ' '); // 问题六
            $templateProcessor->setValue('questionOneSevenMs', ' '); // 问题七
            $templateProcessor->setValue('questionOneEightMs', ' '); // 问题八
            $templateProcessor->setValue('questionOneNineMs', ' '); // 问题九
            $templateProcessor->setValue('questionOneTentMs', ' '); // 问题十
            /*精神状态概况问卷-结束*/
        }

        /**精神状态-结束**/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/basic_all/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取自评档案概况信息
     * @param $data
     * @return array|false
     */
    public function selfEvaluationInfo($data): bool|array
    {
        try {
            $selfTesting = new SelfTestingService($this->app);
            if(!$selfTesting->getOverview($data)) throw new \Exception($selfTesting->getMessage());
            $tempResult = $selfTesting->getResult();
            $ret['user_info'] = $tempResult['user_info']->toArray();
            $ret['archives'] = $tempResult['archives'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 获取用户基本信息
     * @param $data
     * @param $templateProcessor
     * @return mixed
     */
    public function getUserInfo($data, $templateProcessor): mixed
    {
        $sex = $this->getSex($data['user_info']);
        $tempInfo = new UserService($this->app);
        $studentStatus = $tempInfo->getStudentStatusSelector();//获取所有学籍状态
        $region = $data['user_info']['province_name'].$data['user_info']['city_name'].$data['user_info']['area_name'];
        $templateProcessor->setValue('name', $data['user_info']['name']); // 用户姓名
        $templateProcessor->setValue('username', $data['user_info']['username']); // 用户账号
        $templateProcessor->setValue('type', '普通用户'); // 账号类型
        $templateProcessor->setValue('age', $data['user_info']['age']); // 实际年龄
        $templateProcessor->setValue('pessimistic', $data['user_info']['phone']); // 联系电话
        $templateProcessor->setValue('sex', $sex); // 用户性别
        $templateProcessor->setValue('region', $region); // 所在区域
        $templateProcessor->setValue('unit', $data['user_info']['unit_name']); // 所在单位
        $templateProcessor->setValue('class', $data['user_info']['department_name']); // 所在部门
        $templateProcessor->setValue('number', $data['user_info']['user_number']); // 用户编号
        $templateProcessor->setValue('Dadmin', $data['user_info']['department_admin']); // 部门管理员
        $templateProcessor->setValue('status', $studentStatus[$data['user_info']['student_status']]['value']); // 学籍状态
        return $templateProcessor;
    }

    /**
     * 导出自评档案概况
     * @param $data
     * @return string
     */
    public function exportSelfEvaluation($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/SelfEvaluation.docx');
        $templateProcessor->setValue('title', '自评档案概况'); // 档案标题
        $templateProcessor->setValue('end_time', date('Y年m月d日',$data['archives']['max_time'])); // 档案最后更新时间

        /*用户基本信息-开始*/
        $this->getUserInfo($data,$templateProcessor);
        /*用户基本信息-结束*/

        /*档案统计-开始*/
        $min_time = date('Y年m月d日',$data['archives']['min_time']);
        $introduction = '本档案首次建立于：'.$min_time.'，距现在'.$data['archives']['to_date'].'天。在此期间，该用户共进行自评：'.$data['archives']['total'].'次。';
        $asFollows = '自评报告来源渠道如下：';
        $templateProcessor->setValue('introduction', $introduction); // 介绍
        $templateProcessor->setValue('asFollows', $asFollows); // 下图

        $templateProcessor->setValue('total', $data['archives']['total']); // 全部
        $total_proportion = '0%';
        if(!empty($data['archives']['total'])) $total_proportion = $data['archives']['total_proportion'].'%';
        $templateProcessor->setValue('tp', $total_proportion); //

        $templateProcessor->setValue('self', empty($data['archives']['self'])?' 0':$data['archives']['self']); // 用户手动更新资料
        $self_proportion = '0%';
        if(!empty($data['archives']['self'])) $self_proportion = $data['archives']['self_proportion'].'%';
        $templateProcessor->setValue('sp', $self_proportion); //

        $templateProcessor->setValue('online', empty($data['archives']['online'])?' 0':$data['archives']['online']); // 线上咨询
        $online_proportion = '0%';
        if(!empty($data['archives']['online'])) $online_proportion = $data['archives']['online_proportion'].'%';
        $templateProcessor->setValue('op', $online_proportion); //

        $templateProcessor->setValue('offline', empty($data['archives']['offline'])?' 0':$data['archives']['offline']); // 线下预约
        $offline_proportion = '0%';
        if(!empty($data['archives']['offline'])) $offline_proportion = $data['archives']['offline_proportion'].'%';
        $templateProcessor->setValue('fp', $offline_proportion); //

        $templateProcessor->setValue('team', empty($data['archives']['team'])?' 0':$data['archives']['team']); // 团体
        $team_proportion = '0%';
        if(!empty($data['archives']['team'])) $team_proportion = $data['archives']['team_proportion'].'%';
        $templateProcessor->setValue('mp', $team_proportion); //团体占比
        /*档案统计-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/self_evaluation/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取个人自评记录
     * @param $data
     * @return array|false
     */
    public function selfEvaluationRecordInfo($data): bool|array
    {
        try {
            $data['page'] = 1;
            $data['pageSize'] = 99999999999;
            $selfTesting = new SelfTestingService($this->app);
            if(!$selfTesting->getRecode($data)) throw new \Exception($selfTesting->getMessage());
            $tempResult = $selfTesting->getResult();
            $jsonString = json_encode($tempResult);
            return json_decode($jsonString, true);
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出个人自评记录
     * @param $data
     * @return string
     */
    public function exportSelfEvaluationRecord($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/SelfEvaluationRecord.docx');
        $templateProcessor->setValue('record_title', '个人自评记录'); // 档案标题
        $templateProcessor->setValue('record_end_time', date('Y年m月d日',$data['data'][0]['time'])); // 档案最后更新时间

        $remark = '用户共更新个人自评记录：'.$data['total'].'次。每次更新记录如下：';
        $templateProcessor->setValue('record_remark', $remark);
        /*个人自评记录-开始*/
        $templateProcessor->cloneBlock('result_block', count($data['data']), true, true);
        foreach($data['data'] as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('record_time#' . $index, date('Y年m月d日',$value['time']));  //时间
            $templateProcessor->setValue('record_num#' . $index, '第'.$value['num'].'次');  //第几次
            $templateProcessor->setValue('record_source#' . $index, $value['source']);  //自评记录来源
            $templateProcessor->setValue('record_user_name#' . $index, $value['user_name']); //负责咨询师
            $templateProcessor->setValue('record_describe#' . $index, $value['describe']); //记录来源说明
            $templateProcessor->setValue('blank#' . $index, ' '); //空格
        }
        /*个人自评记录-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/self_evaluation_record/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 导出所有个人自评档案信息
     * @param $data
     * @return string
     */
    public function exportAllSelfEvaluation($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/SelfEvaluationAll.docx');

        /**自评档案概况-开始**/
        $templateProcessor->setValue('title', '自评档案概况'); // 档案标题
        $templateProcessor->setValue('end_time', date('Y年m月d日',$data['self_evaluation_info']['archives']['max_time'])); // 档案最后更新时间

        /*用户基本信息-开始*/
        $this->getUserInfo($data['self_evaluation_info'],$templateProcessor);
        /*用户基本信息-结束*/

        /*档案统计-开始*/
        $min_time = date('Y年m月d日',$data['self_evaluation_info']['archives']['min_time']);
        $introduction = '本档案首次建立于：'.$min_time.'，距现在'.$data['self_evaluation_info']['archives']['to_date'].'天。在此期间，该用户共进行自评：'.$data['self_evaluation_info']['archives']['total'].'次。';
        $asFollows = '自评报告来源渠道如下：';
        $templateProcessor->setValue('introduction', $introduction); // 介绍
        $templateProcessor->setValue('asFollows', $asFollows); // 下图
        $templateProcessor->setValue('total', $data['self_evaluation_info']['archives']['total']); // 全部
        $total_proportion = '0%';
        if(!empty($data['self_evaluation_info']['archives']['total'])) $total_proportion = $data['self_evaluation_info']['archives']['total_proportion'].'%';
        $templateProcessor->setValue('tp', $total_proportion); //

        $templateProcessor->setValue('self', empty($data['self_evaluation_info']['archives']['self'])?' 0':$data['self_evaluation_info']['archives']['self']); // 用户手动更新资料
        $self_proportion = '0%';
        if(!empty($data['self_evaluation_info']['archives']['self'])) $self_proportion = $data['self_evaluation_info']['archives']['self_proportion'].'%';
        $templateProcessor->setValue('sp', $self_proportion); //

        $templateProcessor->setValue('online', empty($data['self_evaluation_info']['archives']['online'])?' 0':$data['self_evaluation_info']['archives']['online']); // 线上咨询
        $online_proportion = '0%';
        if(!empty($data['self_evaluation_info']['archives']['online'])) $online_proportion = $data['self_evaluation_info']['archives']['online_proportion'].'%';
        $templateProcessor->setValue('op', $online_proportion); //

        $templateProcessor->setValue('offline', empty($data['self_evaluation_info']['archives']['offline'])?' 0':$data['self_evaluation_info']['archives']['offline']); // 线下预约
        $offline_proportion = '0%';
        if(!empty($data['self_evaluation_info']['archives']['offline'])) $offline_proportion = $data['self_evaluation_info']['archives']['offline_proportion'].'%';
        $templateProcessor->setValue('fp', $offline_proportion); //

        $templateProcessor->setValue('team', empty($data['self_evaluation_info']['archives']['team'])?' 0':$data['self_evaluation_info']['archives']['team']); // 团体
        $team_proportion = '0%';
        if(!empty($data['self_evaluation_info']['archives']['team'])) $team_proportion = $data['self_evaluation_info']['archives']['team_proportion'].'%';
        $templateProcessor->setValue('mp', $team_proportion); //团体占比
        /*档案统计-结束*/
        /**自评档案概况-结束**/

        /**个人自评记录-开始**/
        $templateProcessor->setValue('record_title', '个人自评记录'); // 档案标题
        $templateProcessor->setValue('record_end_time', date('Y年m月d日',$data['self_evaluation_record_info']['data'][0]['time'])); // 档案最后更新时间

        $remark = '用户共更新个人自评记录：'.$data['self_evaluation_record_info']['total'].'次。每次更新记录如下：';
        $templateProcessor->setValue('record_remark', $remark);  //学历程度
        /*个人自评记录-开始*/
        $templateProcessor->cloneBlock('result_block', count($data['self_evaluation_record_info']['data']), true, true);
        foreach($data['self_evaluation_record_info']['data'] as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('record_time#' . $index, date('Y年m月d日',$value['time']));  //时间
            $templateProcessor->setValue('record_num#' . $index, '第'.$value['num'].'次');  //第几次
            $templateProcessor->setValue('record_source#' . $index, $value['source']);  //自评记录来源
            $templateProcessor->setValue('record_user_name#' . $index, $value['consult_name']??' '); //负责咨询师
            $templateProcessor->setValue('record_describe#' . $index, $value['describe']); //记录来源说明
            $templateProcessor->setValue('blank#' . $index, ' '); //空格
        }
        /*个人自评记录-结束*/
        /**个人自评记录-结束**/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/self_evaluation_record_all/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取测评档案概况信息
     * @param $data
     * @return array|false
     */
    public function evaluationInfo($data): bool|array
    {
        try {
            $EvaluationArchive = new EvaluationArchiveService($this->app);
            if(!$EvaluationArchive->getOverview($data)) throw new \Exception($EvaluationArchive->getMessage());
            $tempResult = $EvaluationArchive->getResult();
            $ret['user_info'] = $tempResult['user_info']->toArray();
            $ret['archives'] = $tempResult['archives'];
            $ret['img'] = $data['img'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出测评档案概况
     * @param $data
     * @return string
     */
    public function exportEvaluation($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/Evaluation.docx');
        $templateProcessor->setValue('title', '测评档案概况'); // 档案标题
        $templateProcessor->setValue('end_time', date('Y年m月d日',$data['archives']['max_time'])); // 档案最后更新时间

        /*用户基本信息-开始*/
        $this->getUserInfo($data,$templateProcessor);
        /*用户基本信息-结束*/
        /*档案统计-开始*/
        $min_time = date('Y年m月d日',$data['archives']['min_time']);
        $introduction = '本档案首次建立于：'.$min_time.'，距现在'.$data['archives']['to_date'].'天。在此期间，该用户共进行自评：'.$data['archives']['total'].'份。';
        $asFollows = '各类型报告数量如下：';
        $templateProcessor->setValue('introduction', $introduction); // 介绍
        $templateProcessor->setValue('asFollows', $asFollows); // 如下
        $templateProcessor->setValue('total', $data['archives']['total']); // 全部
        $total_proportion = '0%';
        if(!empty($data['archives']['total'])) $total_proportion = $data['archives']['waring_proportion'].'%';
        $templateProcessor->setValue('tp', $total_proportion); //

        $templateProcessor->setValue('self', empty($data['archives']['waring_self'])?' 0':$data['archives']['waring_self']); // 自我测评任务报告
        $self_proportion = '0%';
        if(!empty($data['archives']['waring_self'])) $self_proportion = $data['archives']['waring_self_proportion'].'%';
        $templateProcessor->setValue('sp', $self_proportion); //

        $templateProcessor->setValue('task', empty($data['archives']['waring_task'])?' 0':$data['archives']['waring_task']); // 任务测评任务报告
        $waring_task_proportion = '0%';
        if(!empty($data['archives']['waring_task'])) $waring_task_proportion = $data['archives']['waring_task_proportion'].'%';
        $templateProcessor->setValue('op', $waring_task_proportion); //

        $templateProcessor->setValue('proxy', empty($data['archives']['waring_proxy'])?' 0':$data['archives']['waring_proxy']); // 他人代测报告
        $proxy_proportion = '0%';
        if(!empty($data['archives']['waring_proxy'])) $proxy_proportion = $data['archives']['waring_proxy_proportion'].'%';
        $templateProcessor->setValue('fp', $proxy_proportion); //

        $templateProcessor->setValue('wireless', empty($data['archives']['waring_wireless'])?' 0':$data['archives']['waring_wireless']); // 无线测评报告
        $wireless_proportion = '0%';
        if(!empty($data['archives']['waring_wireless'])) $wireless_proportion = $data['archives']['waring_wireless_proportion'].'%';
        $templateProcessor->setValue('mp', $wireless_proportion); //

        $templateProcessor->setValue('StatisticalChart', '各类型报告中，预警报告占比数量统计如下：'); //统计图上面的话
        if(empty($data['img'])){
            $templateProcessor->setValue('img', ''); //
        }else{
            $templateProcessor->setImageValue('img', ['path' => $data['img'][0], 'width' => 600, 'height' => 400]);
        }
        /*档案统计-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/evaluation/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取自我测评记录
     * @param $data
     * @return array|false
     */
    public function EvaluationRecordInfo($data): bool|array
    {
        try {
            $data['page'] = 1;
            $data['pageSize'] = 99999999999;
            $EvaluationArchive = new EvaluationArchiveService($this->app);
            if(!$EvaluationArchive->getSelfRecode($data)) throw new \Exception($EvaluationArchive->getMessage());
            $tempResult = $EvaluationArchive->getResult();
            $ret['list'] = $tempResult['items'];
            $ret['total'] = $tempResult['meta']['recode_total'];
            $ret['warning_num'] = $tempResult['meta']['warning_num'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出自我测评记录
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportEvaluationRecord($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/EvaluationRecord.docx');

        //数据处理
        $list = array_values($data['list']);
        $templateProcessor->setValue('evaluation_record_title', '自我测评报告记录'); // 档案标题
        $templateProcessor->setValue('evaluation_record_end_time', date('Y年m月d日',$list[0][0]['time'])); // 档案最后更新时间

        $remark = '档案内共有自我测评报告记录：'.$data['total'].'条。预警报告记录：'.$data['warning_num'].'条,任务记录如下：';
        $templateProcessor->setValue('record_remark', $remark);  //
        /*自我测评记录-开始*/
        $templateProcessor->cloneBlock('result_block', count($data['list']), true, true);
        foreach($list as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('record_time#' . $index, date('Y年m月',$value[$key]['time']).'任务记录');  //时间
            $templateProcessor->cloneRow('num#' . $index, count($value));
            foreach($value as $k=>$v){
                $i = $k+1;
                $templateProcessor->setValue('num#'. $index .'#'. $i, $v['number']);//序号
                $templateProcessor->setImageValue('img#' . $index .'#' . $i, ['path' => $v['rating_scale_cover'], 'width' => 60, 'height' => 20]);//量表图片
                $templateProcessor->setValue('ratingScaleName#'. $index .'#' . $i, $v['rating_scale_name']);//测评量表名称
                $templateProcessor->setValue('scaleType#'. $index .'#' . $i, $v['rating_scale_type_name']);//测评量表分类
                if($v['is_warning'] == 0){
                    $is_warning = '无预警';
                }else{
                    $is_warning = '有预警';
                }
                $templateProcessor->setValue('waring#'. $index .'#' . $i, $is_warning);//报告预警
                $templateProcessor->setValue('addTime#'. $index .'#' . $i, date('Y-m-d H:i:s',$v['time']));//任务报告生成时间
            }
            $templateProcessor->setValue('blank#' . $index, ' '); //空格
        }
        /*自我测评记录-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/evaluation_record/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取任务测评记录
     * @param $data
     * @return array|false
     */
    public function taskEvaluationRecordInfo($data): bool|array
    {
        try {
            $data['page'] = 1;
            $data['pageSize'] = 99999999999;
            $EvaluationArchive = new EvaluationArchiveService($this->app);
            if(!$EvaluationArchive->getTaskRecode($data)) throw new \Exception($EvaluationArchive->getMessage());
            $tempResult = $EvaluationArchive->getResult();
            $ret['list'] = $tempResult['items'];
            $ret['total'] = $tempResult['meta']['recode_total'];
            $ret['warning_num'] = $tempResult['meta']['warning_num'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出任务测评记录
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportTaskEvaluationRecord($data): string
    {

        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/TaskEvaluationRecord.docx');

        //数据处理
        $list = array_values($data['list']);
        $templateProcessor->setValue('task_evaluation_record_title', '任务测评报告记录'); // 档案标题
        $templateProcessor->setValue('task_evaluation_record_end_time', date('Y年m月d日',$list[0][0]['end_time'])); // 档案最后更新时间

        $remark = '档案内共有任务测评报告记录：'.$data['total'].'条。预警报告记录：'.$data['warning_num'].'条,任务记录如下：';
        $templateProcessor->setValue('record_remark', $remark);  //
        /*任务测评记录-开始*/
        $templateProcessor->cloneBlock('result_block', count($data['list']), true, true);
        foreach($list as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('record_time#' . $index, date('Y年m月',$value[$key]['end_time']).'任务记录');  //时间
            $templateProcessor->cloneRow('num#' . $index, count($value));
            foreach($value as $k=>$v){
                $i = $k+1;
                $templateProcessor->setValue('num#'. $index .'#'. $i, $v['number']);//序号
                $templateProcessor->setValue('ratingScaleName#'. $index .'#' . $i, $v['name']);//测评任务名称
                $templateProcessor->setValue('scaleNum#'. $index .'#' . $i, $v['rating_scale_count'].'个');//任务包含量表
                if($v['is_warning'] == 0){
                    $is_warning = '无预警';
                }else{
                    $is_warning = '有预警';
                }
                $templateProcessor->setValue('waring#'. $index .'#' . $i, $is_warning);//报告预警
                $templateProcessor->setValue('endTime#'. $index .'#' . $i, date('Y-m-d H:i:s',$v['end_time']));//任务完成时间
            }
            $templateProcessor->setValue('blank#' . $index, ' '); //空格
        }
        /*任务测评记录-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/task_evaluation_record/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取他人代评记录
     * @param $data
     * @return array|false
     */
    public function othersEvaluationRecordInfo($data): bool|array
    {
        try {
            $data['page'] = 1;
            $data['pageSize'] = 99999999999;
            $EvaluationArchive = new EvaluationArchiveService($this->app);
            if(!$EvaluationArchive->getProxyRecode($data)) throw new \Exception($EvaluationArchive->getMessage());
            $tempResult = $EvaluationArchive->getResult();
            $ret['list'] = $tempResult['items'];
            $ret['total'] = $tempResult['meta']['recode_total'];
            $ret['warning_num'] = $tempResult['meta']['warning_num'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出他人代评记录
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportOthersEvaluationRecord($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/OthersEvaluationRecord.docx');

        //数据处理
        $list = array_values($data['list']);
        $templateProcessor->setValue('others_evaluation_record_title', '他人代评记录'); // 档案标题
        $templateProcessor->setValue('others_evaluation_record_end_time', date('Y年m月d日',$list[0][0]['time'])); // 档案最后更新时间

        $remark = '档案内共有他人代评报告记录：'.$data['total'].'条。预警报告记录：'.$data['warning_num'].'条,任务记录如下：';
        $templateProcessor->setValue('record_remark', $remark);  //
        /*任务测评记录-开始*/
        $templateProcessor->cloneBlock('result_block', count($data['list']), true, true);
        foreach($list as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('record_time#' . $index, date('Y年m月',$value[$key]['time']).'任务记录');  //时间
            $templateProcessor->cloneRow('num#' . $index, count($value));
            foreach($value as $k=>$v){
                $i = $k+1;
                $templateProcessor->setValue('num#'. $index .'#'. $i, $v['number']);//序号
                $templateProcessor->setImageValue('img#' . $index .'#' . $i, ['path' => $v['rating_scale_cover'], 'width' => 60, 'height' => 20]);//量表图片
                $templateProcessor->setValue('ratingSN#'. $index .'#' . $i, $v['rating_scale_name']);//测评量表名称
                $templateProcessor->setValue('scaleType#'. $index .'#' . $i, $v['rating_scale_type_name']);//测评量表分类
                if($v['is_warning'] == 0){
                    $is_warning = '无预警';
                }else{
                    $is_warning = '有预警';
                }
                $templateProcessor->setValue('waring#'. $index .'#' . $i, $is_warning);//报告预警
                $templateProcessor->setValue('addTime#'. $index .'#' . $i, date('Y-m-d H:i:s',$v['time']));//任务报告生成时间
                $templateProcessor->setValue('proxyN#'. $index .'#' . $i, $v['proxy_name']);//代评人姓名
            }
            $templateProcessor->setValue('blank#' . $index, ' '); //空格
        }
        /*任务测评记录-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/others_evaluation_record/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 导出所有测评档案
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportAllScaleRecord($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/EvaluationAll.docx');

        /**测评档案概况**/
        $templateProcessor->setValue('title', '测评档案概况'); // 档案标题
        $templateProcessor->setValue('end_time', date('Y年m月d日',$data['evaluation_info']['archives']['max_time'])); // 档案最后更新时间

        /*用户基本信息-开始*/
        $this->getUserInfo($data['evaluation_info'],$templateProcessor);
        /*用户基本信息-结束*/
        /*档案统计-开始*/
        $min_time = date('Y年m月d日',$data['evaluation_info']['archives']['min_time']);
        $introduction = '本档案首次建立于：'.$min_time.'，距现在'.$data['evaluation_info']['archives']['to_date'].'天。在此期间，该用户共进行自评：'.$data['evaluation_info']['archives']['total'].'份。';
        $asFollows = '各类型报告数量如下：';
        $templateProcessor->setValue('introduction', $introduction); // 介绍
        $templateProcessor->setValue('asFollows', $asFollows); // 如下
        $templateProcessor->setValue('total', $data['evaluation_info']['archives']['total']); // 全部
        $total_proportion = '0%';
        if(!empty($data['evaluation_info']['archives']['total'])) $total_proportion = $data['evaluation_info']['archives']['waring_proportion'].'%';
        $templateProcessor->setValue('tp', $total_proportion); //

        $templateProcessor->setValue('self', empty($data['evaluation_info']['archives']['waring_self'])?' 0':$data['evaluation_info']['archives']['waring_self']); // 自我测评任务报告
        $self_proportion = '0%';
        if(!empty($data['evaluation_info']['archives']['waring_self'])) $self_proportion = $data['evaluation_info']['archives']['waring_self_proportion'].'%';
        $templateProcessor->setValue('sp', $self_proportion); //

        $templateProcessor->setValue('task', empty($data['evaluation_info']['archives']['waring_task'])?' 0':$data['evaluation_info']['archives']['waring_task']); // 任务测评任务报告
        $waring_task_proportion = '0%';
        if(!empty($data['evaluation_info']['archives']['waring_task'])) $waring_task_proportion = $data['evaluation_info']['archives']['waring_task_proportion'].'%';
        $templateProcessor->setValue('op', $waring_task_proportion); //

        $templateProcessor->setValue('proxy', empty($data['evaluation_info']['archives']['waring_proxy'])?' 0':$data['evaluation_info']['archives']['waring_proxy']); // 他人代测报告
        $proxy_proportion = '0%';
        if(!empty($data['evaluation_info']['archives']['waring_proxy'])) $proxy_proportion = $data['evaluation_info']['archives']['waring_proxy_proportion'].'%';
        $templateProcessor->setValue('fp', $proxy_proportion); //

        $templateProcessor->setValue('wireless', empty($data['evaluation_info']['archives']['waring_wireless'])?' 0':$data['evaluation_info']['archives']['waring_wireless']); // 无线测评报告
        $wireless_proportion = '0%';
        if(!empty($data['evaluation_info']['archives']['waring_wireless'])) $wireless_proportion = $data['evaluation_info']['archives']['waring_wireless_proportion'].'%';
        $templateProcessor->setValue('mp', $wireless_proportion); //

        $templateProcessor->setValue('StatisticalChart', '各类型报告中，预警报告占比数量统计如下：'); //统计图上面的话
        if(empty($data['evaluation_info']['img'])){
            $templateProcessor->setValue('img', ''); //
        }else{
            $templateProcessor->setImageValue('img', ['path' => $data['evaluation_info']['img'][0], 'width' => 600, 'height' => 400]);
        }
        /*档案统计-结束*/
        /**测评档案概况**/

        /**自我测评记录**/
        if(empty($data['evaluation_record_info'])){
            //无数据
            $templateProcessor->setValue('evaluation_record_title', '自我测评报告记录'); // 档案标题
            $templateProcessor->setValue('evaluation_record_end_time', '暂无时间'); // 档案最后更新时间
            $remark = '档案内共有自我测评报告记录：0条。预警报告记录：0条,任务记录如下：';
            $templateProcessor->setValue('record_remark', $remark);  //
            /*任务测评记录-开始*/
            $templateProcessor->cloneBlock('result_block', 1, true, true);
            $templateProcessor->setValue('record_time#1', ' ');  //时间
            $templateProcessor->setValue('num#1', ' ');//序号
            $templateProcessor->setValue('imgs#1', ' ');//量表图片
            $templateProcessor->setValue('ratingScaleName#1', ' ');//测评量表名称
            $templateProcessor->setValue('scaleType#1', ' ');//测评量表分类
            $templateProcessor->setValue('waring#1', ' ');//报告预警
            $templateProcessor->setValue('addTime#1', ' ');//任务报告生成时间

            $templateProcessor->setValue('blank#1' , ' '); //空格
        }
        else{
            //数据处理
            $list = array_values($data['evaluation_record_info']['list']);
            $templateProcessor->setValue('evaluation_record_title', '自我测评报告记录'); // 档案标题
            $templateProcessor->setValue('evaluation_record_end_time', date('Y年m月d日',$list[0][0]['time'])); // 档案最后更新时间
            $remark = '档案内共有自我测评报告记录：'.$data['evaluation_record_info']['total'].'条。预警报告记录：'.$data['evaluation_record_info']['warning_num'].'条,任务记录如下：';
            $templateProcessor->setValue('record_remark', $remark);  //
            /*自我测评记录-开始*/
            $templateProcessor->cloneBlock('result_block', count($data['evaluation_record_info']['list']), true, true);
            foreach($list as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('record_time#' . $index, date('Y年m月',$value[$key]['time']).'任务记录');  //时间
                $templateProcessor->cloneRow('num#' . $index, count($value));
                foreach($value as $k=>$v){
                    $i = $k+1;
                    $templateProcessor->setValue('num#'. $index .'#'. $i, $v['number']);//序号
                    $templateProcessor->setImageValue('imgs#' . $index .'#' . $i, ['path' => $v['rating_scale_cover'], 'width' => 60, 'height' => 20]);//量表图片
                    $templateProcessor->setValue('ratingScaleName#'. $index .'#' . $i, $v['rating_scale_name']);//测评量表名称
                    $templateProcessor->setValue('scaleType#'. $index .'#' . $i, $v['rating_scale_type_name']);//测评量表分类
                    if($v['is_warning'] == 0){
                        $is_warning = '无预警';
                    }else{
                        $is_warning = '有预警';
                    }
                    $templateProcessor->setValue('waring#'. $index .'#' . $i, $is_warning);//报告预警
                    $templateProcessor->setValue('addTime#'. $index .'#' . $i, date('Y-m-d H:i:s',$v['time']));//任务报告生成时间
                }

                $templateProcessor->setValue('blank#' . $index, ' '); //空格
            }
            /*自我测评记录-结束*/
        }
        /**自我测评记录**/

        /**任务测评记录**/
        if(empty($data['task_evaluation_record_info'])){
            //无数据
            $templateProcessor->setValue('task_evaluation_record_title', '任务测评报告记录'); // 档案标题
            $templateProcessor->setValue('task_evaluation_record_end_time', '暂无时间'); // 档案最后更新时间
            $remark = '档案内共有任务测评报告记录：0条。预警报告记录：0条,任务记录如下：';
            $templateProcessor->setValue('record_remarks', $remark);  //
            /*任务测评记录-开始*/
            $templateProcessor->cloneBlock('result_blocks', 1, true, true);
            $templateProcessor->setValue('record_times#1', ' ');  //时间
            $templateProcessor->setValue('nut#1', ' ');//序号
            $templateProcessor->setValue('ratingScaleNames#1', ' ');//测评任务名称
            $templateProcessor->setValue('scaleNum#1', ' ');//任务包含量表
            $templateProcessor->setValue('warings#1', ' ');//报告预警
            $templateProcessor->setValue('endTime#1', ' ');//任务报告生成时间

            $templateProcessor->setValue('blanks#1' , ' '); //空格
        }
        else{
            //数据处理
            $list = array_values($data['task_evaluation_record_info']['list']);
            $templateProcessor->setValue('task_evaluation_record_title', '任务测评报告记录'); // 档案标题
            $templateProcessor->setValue('task_evaluation_record_end_time', date('Y年m月d日',$list[0][0]['end_time'])); // 档案最后更新时间

            $remark = '档案内共有任务测评报告记录：'.$data['task_evaluation_record_info']['total'].'条。预警报告记录：'.$data['task_evaluation_record_info']['warning_num'].'条,任务记录如下：';
            $templateProcessor->setValue('record_remarks', $remark);  //
            /*任务测评记录-开始*/
            $templateProcessor->cloneBlock('result_blocks', count($data['task_evaluation_record_info']['list']), true, true);
            foreach($list as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('record_times#' . $index, date('Y年m月',$value[$key]['end_time']).'任务记录');  //时间
                $templateProcessor->cloneRow('nut#' . $index, count($value));
                foreach($value as $k=>$v){
                    $i = $k+1;
                    $templateProcessor->setValue('nut#'. $index .'#'. $i, $v['number']);//序号
                    $templateProcessor->setValue('ratingScaleNames#'. $index .'#' . $i, $v['name']);//测评任务名称
                    $templateProcessor->setValue('scaleNum#'. $index .'#' . $i, $v['rating_scale_count'].'个');//任务包含量表
                    if($v['is_warning'] == 0){
                        $is_warning = '无预警';
                    }else{
                        $is_warning = '有预警';
                    }
                    $templateProcessor->setValue('warings#'. $index .'#' . $i, $is_warning);//报告预警
                    $templateProcessor->setValue('endTime#'. $index .'#' . $i, date('Y-m-d H:i:s',$v['end_time']));//任务完成时间
                }
                $templateProcessor->setValue('blanks#' . $index, ' '); //空格
            }
            /*任务测评记录-结束*/
        }
        /**任务测评记录**/

        /**他人代评记录**/
        if(empty($data['others_evaluation_record_info'])){
            //无数据
            $templateProcessor->setValue('others_evaluation_record_title', '他人代评记录'); // 档案标题
            $templateProcessor->setValue('others_evaluation_record_end_time', '暂无时间'); // 档案最后更新时间
            $remark = '档案内共有他人代评报告记录：0条。预警报告记录：0条,任务记录如下：';
            $templateProcessor->setValue('record_remarke', $remark);  //
            /*任务测评记录-开始*/
            $templateProcessor->cloneBlock('result_blocke', 1, true, true);
            $templateProcessor->setValue('record_timee#1', ' ');  //时间
            $templateProcessor->setValue('nue#1', ' ');//序号
            $templateProcessor->setValue('imge#1', ' ');//量表图片
            $templateProcessor->setValue('ratingSN#1', ' ');//测评量表名称
            $templateProcessor->setValue('scaleT#1', ' ');//测评量表分类
            $templateProcessor->setValue('waringe#1', ' ');//报告预警
            $templateProcessor->setValue('addTimee#1', ' ');//任务报告生成时间
            $templateProcessor->setValue('proxyN#1', ' ');//代评人姓名

            $templateProcessor->setValue('blanke#1' , ' '); //空格
        }
        else{
            //数据处理
            $list = array_values($data['others_evaluation_record_info']['list']);
            $templateProcessor->setValue('others_evaluation_record_title', '他人代评记录'); // 档案标题
            $templateProcessor->setValue('others_evaluation_record_end_time', date('Y年m月d日',$list[0][0]['time'])); // 档案最后更新时间

            $remark = '档案内共有他人代评报告记录：'.$data['others_evaluation_record_info']['total'].'条。预警报告记录：'.$data['others_evaluation_record_info']['warning_num'].'条,任务记录如下：';
            $templateProcessor->setValue('record_remarke', $remark);  //

            /*任务测评记录-开始*/
            $templateProcessor->cloneBlock('result_blocke', count($data['others_evaluation_record_info']['list']), true, true);
            foreach($list as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('record_timee#' . $index, date('Y年m月',$value[$key]['time']).'任务记录');  //时间
                $templateProcessor->cloneRow('nue#' . $index, count($value));
                foreach($value as $k=>$v){
                    $i = $k+1;
                    $templateProcessor->setValue('nue#'. $index .'#'. $i, $v['number']);//序号
                    $templateProcessor->setImageValue('imge#' . $index .'#' . $i, ['path' => $v['rating_scale_cover'], 'width' => 60, 'height' => 20]);//量表图片
                    $templateProcessor->setValue('ratingSN#'. $index .'#' . $i, $v['rating_scale_name']);//测评量表名称
                    $templateProcessor->setValue('scaleT#'. $index .'#' . $i, $v['rating_scale_type_name']);//测评量表分类
                    if($v['is_warning'] == 0){
                        $is_warning = '无预警';
                    }else{
                        $is_warning = '有预警';
                    }
                    $templateProcessor->setValue('waringe#'. $index .'#' . $i, $is_warning);//报告预警
                    $templateProcessor->setValue('addTimee#'. $index .'#' . $i, date('Y-m-d H:i:s',$v['time']));//任务报告生成时间
                    $templateProcessor->setValue('proxyN#'. $index .'#' . $i, $v['proxy_name']);//代评人姓名
                }
                $templateProcessor->setValue('blanke#' . $index, ' '); //空格
            }
            /*任务测评记录-结束*/
        }
        /**他人代评记录**/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/evaluationAll/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取危机个干预概况
     * @param $data
     * @return array|false
     */
    public function interfereInfo($data): bool|array
    {
        try {
            $crisisTesting = new CrisisTestingService($this->app);
            if(!$crisisTesting->getOverview($data)) throw new \Exception($crisisTesting->getMessage());
            $tempResult = $crisisTesting->getResult();
            $ret['user_info'] = $tempResult['user_info']->toArray();
            $ret['intervention_overview'] = $tempResult['intervention_overview'];
            $ret['img'] = $data['img'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出危机干预概况
     * @param $data
     * @return string
     */
    public function exportInterfere($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/Interfere.docx');
        $templateProcessor->setValue('title', '干预档案概况'); // 档案标题
        $templateProcessor->setValue('end_time', date('Y年m月d日',$data['intervention_overview']['max_time'])); // 档案最后更新时间

        /*用户基本信息-开始*/
        $this->getUserInfo($data,$templateProcessor);
        /*用户基本信息-结束*/

        /*危机干预统计-开始*/
        $min_time = date('Y年m月d日',$data['intervention_overview']['min_time']);
        $introduction = '本档案首次建立于：'.$min_time.'，距现在'.$data['intervention_overview']['to_date'].'天。在此期间，该用户共归危机档干预记录：'.$data['intervention_overview']['total'].'条。';
        $asFollows = '危机干预来源渠道如下：';
        $templateProcessor->setValue('introduction', $introduction); // 介绍
        $templateProcessor->setValue('asFollows', $asFollows); // 如下

        if(empty($data['img'])){
            $templateProcessor->setValue('img', ''); //
        }else{
            $templateProcessor->setImageValue('img', ['path' => $data['img'][0], 'width' => 600, 'height' => 400]);//统计图
        }
        /*危机干预统计-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/interfere/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取危机干预记录
     * @param $data
     * @return array|false
     */
    public function interfereRecordInfo($data): bool|array
    {
        try {
            $data['page'] = 1;
            $data['pageSize'] = 99999999999;
            $crisisTesting = new CrisisTestingService($this->app);
            if(!$crisisTesting->getCrisisRecode($data)) throw new \Exception($crisisTesting->getMessage());
            $tempResult = $crisisTesting->getResult();
            $jsonString = json_encode($tempResult);
            return json_decode($jsonString, true);
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出危机干预记录
     * @param $data
     * @return string
     */
    public function exportInterfereRecord($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/InterfereRecord.docx');

        $templateProcessor->setValue('interfere_record_title', '危机干预记录'); // 档案标题
        $templateProcessor->setValue('interfere_record_end_time', date('Y年m月d日',$data['data'][0]['status_time'])); // 档案最后更新时间

        //数据处理
        $remark = '当前系统内共查询到，该用户相关的危机干预记录：'.$data['total'].'条。每条干预记录如下：';
        $templateProcessor->setValue('record_remark', $remark);  //
        /*危机干预记录-开始*/
        $templateProcessor->cloneBlock('result_block', count($data['data']), true, true);
        foreach($data['data'] as $key=>$value) {
            $index = $key + 1;
            $templateProcessor->setValue('record_time#' . $index, '第' . $value['num'] . '次危机干预');  //时间

            $templateProcessor->setValue('level#' . $index, $value['level_name']);  //危机风险等级
            $templateProcessor->setValue('type#' . $index, $value['type_name']);  //疑似问题类型
            $behavior = '';
            foreach($value['InterfereBehavior'] as $item){
                $behavior .= $item['behavior_name'].'、';
            }
            $templateProcessor->setValue('behavior#' . $index, substr_replace($behavior,'',-3));  //异常行为表现
            $upNum = ' 0';
            if($value['up_num'] > 0) $upNum = $value['up_num'];
            $templateProcessor->setValue('upNum#' . $index, $upNum.'次');  //事项共跟进
            if ($value['status'] == 0){
                $status = '未完结';
            }else{
                $status = '已完结';
            }
            $templateProcessor->setValue('over#' . $index, $status);  //是否完结
            $templateProcessor->setValue('endTime#' . $index, date('Y-m-d H:i:s',$value['status_time']));  //归档时间

            $templateProcessor->setValue('blank#' . $index, ' '); //空格
        }
        /*危机干预记录-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/interfere_record/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 导出所有危机干预档案
     * @param $data
     * @return string
     */
    public function exportAllInterfereRecord($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/InterfereAll.docx');

        /**危机干预概况**/
        $templateProcessor->setValue('title', '干预档案概况'); // 档案标题
        $templateProcessor->setValue('end_time', date('Y年m月d日',$data['interfere_info']['intervention_overview']['max_time'])); // 档案最后更新时间

        /*用户基本信息-开始*/
        $this->getUserInfo($data['interfere_info'],$templateProcessor);
        /*用户基本信息-结束*/

        /*危机干预统计-开始*/
        $min_time = date('Y年m月d日',$data['interfere_info']['intervention_overview']['min_time']);
        $introduction = '本档案首次建立于：'.$min_time.'，距现在'.$data['interfere_info']['intervention_overview']['to_date'].'天。在此期间，该用户共归危机档干预记录：'.$data['interfere_info']['intervention_overview']['total'].'条。';
        $asFollows = '危机干预来源渠道如下：';
        $templateProcessor->setValue('introduction', $introduction); // 介绍
        $templateProcessor->setValue('asFollows', $asFollows); // 如下

        if(empty($data['interfere_info']['img'])){
            $templateProcessor->setValue('img', ''); //
        }else{
            $templateProcessor->setImageValue('img', ['path' => $data['interfere_info']['img'][0], 'width' => 600, 'height' => 400]);//统计图
        }
        /*危机干预统计-结束*/
        /**危机干预概况**/

        /**危机干预概况**/
        $templateProcessor->setValue('interfere_record_title', '危机干预记录'); // 档案标题
        $templateProcessor->setValue('interfere_record_end_time', date('Y年m月d日',$data['interfere_record_info']['data'][0]['status_time'])); // 档案最后更新时间

        //数据处理
        $remark = '当前系统内共查询到，该用户相关的危机干预记录：'.$data['interfere_record_info']['total'].'条。每条干预记录如下：';
        $templateProcessor->setValue('record_remark', $remark);  //
        /*危机干预记录-开始*/
        $templateProcessor->cloneBlock('result_block', count($data['interfere_record_info']['data']), true, true);
        foreach($data['interfere_record_info']['data'] as $key=>$value) {
            $index = $key + 1;
            $templateProcessor->setValue('record_time#' . $index, '第' . $value['num'] . '次危机干预');  //时间

            $templateProcessor->setValue('level#' . $index, $value['level_name']);  //危机风险等级
            $templateProcessor->setValue('types#' . $index, $value['type_name']);  //疑似问题类型
            $behavior = '';
            foreach($value['InterfereBehavior'] as $item){
                $behavior .= $item['behavior_name'].'、';
            }
            $templateProcessor->setValue('behavior#' . $index, substr_replace($behavior,'',-3));  //异常行为表现
            $upNum = ' 0';
            if($value['up_num'] > 0) $upNum = $value['up_num'];
            $templateProcessor->setValue('upNum#' . $index, $upNum.'次');  //事项共跟进
            if ($value['status'] == 0){
                $status = '未完结';
            }else{
                $status = '已完结';
            }
            $templateProcessor->setValue('over#' . $index, $status);  //是否完结
            $templateProcessor->setValue('endTime#' . $index, date('Y-m-d H:i:s',$value['status_time']));  //归档时间

            $templateProcessor->setValue('blank#' . $index, ' '); //空格
        }
        /*危机干预记录-结束*/
        /**危机干预记录**/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/interfereAll/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取咨询预约概况
     * @param $data
     * @return array|false
     */
    public function consultInfo($data): bool|array
    {
        try {
            $data['page'] = 1;
            $data['pageSize'] = 99999999999;
            $PsychologicalCounseling = new PsychologicalCounselingService($this->app);
            if(!$PsychologicalCounseling->getOverview($data)) throw new \Exception($PsychologicalCounseling->getMessage());
            $tempResult = $PsychologicalCounseling->getResult();
            $jsonString = json_encode($tempResult);
            $user_info = json_decode($jsonString, true);
            $ret['user_info'] = $user_info['user_info'];
            $ret['psychological'] = $user_info['psychological'];
            $ret['img'] = $data['img'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出咨询预约概况
     * @param $data
     * @return string
     */
    public function exportConsult($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/Consult.docx');
        $templateProcessor->setValue('title', '咨询预约概况'); // 档案标题
        $templateProcessor->setValue('end_time', date('Y年m月d日',$data['psychological']['max_time'])); // 档案最后更新时间

        /*用户基本信息-开始*/
        $this->getUserInfo($data,$templateProcessor);
        /*用户基本信息-结束*/

        /*咨询预约概况-开始*/
        $min_time = date('Y年m月d日',$data['psychological']['min_time']);
        $introduction = '本档案首次建立于：'.$min_time.'，距现在'.$data['psychological']['to_date'].'天。在此期间，该用户共归危机咨询/预约：'.$data['psychological']['total'].'次。';
        $asFollows = '咨询/预约的问题类型如下：';
        $templateProcessor->setValue('introduction', $introduction); // 介绍
        $templateProcessor->setValue('asFollows', $asFollows); // 如下

        if(empty($data['img'])){
            $templateProcessor->setValue('img', ''); //
        }else{
            $templateProcessor->setImageValue('img', ['path' => $data['img'][0], 'width' => 600, 'height' => 400]);//统计图
        }
        /*咨询预约概况-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/consult/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取线上咨询记录
     * @param $data
     * @return array|false
     */
    public function onlineInfo($data): bool|array
    {
        try {
            $data['page'] = 1;
            $data['pageSize'] = 99999999999;
            $PsychologicalCounseling = new PsychologicalCounselingService($this->app);
            if(!$PsychologicalCounseling->getOnlineRecode($data)) throw new \Exception($PsychologicalCounseling->getMessage());
            $tempResult = $PsychologicalCounseling->getResult();
            $ret['list'] = $tempResult['items'];
            $ret['total'] = $tempResult['meta']['total_items'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出线上咨询记录
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportOnline($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/Online.docx');

        //数据处理
        $list = array_values($data['list']);
        $templateProcessor->setValue('online_title', '线上咨询记录'); // 档案标题
        $templateProcessor->setValue('online_end_time', date('Y年m月d日',$list[0][0]['end_time'])); // 档案最后更新时间

        $remark = '当前系统内共查询到，该用户相关的线上咨询记录：'.$data['total'].'条。各咨询记录如下：';
        $templateProcessor->setValue('record_remark', $remark);  //
        /*线上咨询记录-开始*/
        $templateProcessor->cloneBlock('result_block', count($data['list']), true, true);
        foreach($list as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('record_time#' . $index, date('Y年m月',$value[$key]['end_time']).'任务记录');  //时间
            $templateProcessor->cloneRow('num#' . $index, count($value));
            foreach($value as $k=>$v){
                $i = $k+1;
                $templateProcessor->setValue('num#'. $index .'#'. $i, $v['number']);//序号
                $templateProcessor->setValue('onlineType#'. $index .'#' . $i, $v['question_name']);//咨询问题类型
                $templateProcessor->setValue('consultantN#'. $index .'#' . $i, $v['consult_name']);//负责咨询师
                if($v['is_end'] == 0){
                    $isEnd = '未完结';
                }else{
                    $isEnd = '已完结';
                }
                $templateProcessor->setValue('end#'. $index .'#' . $i, $isEnd);//咨询是否完结
                $templateProcessor->setValue('endTime#'. $index .'#' . $i, date('Y-m-d H:i:s',$v['end_time']));//咨询完结时间
            }
            $templateProcessor->setValue('blank#' . $index, ' '); //空格
        }
        /*线上咨询记录-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/online/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取线下预约记录
     * @param $data
     * @return array|false
     */
    public function offlineInfo($data): bool|array
    {
        try {
            $data['page'] = 1;
            $data['pageSize'] = 99999999999;
            $PsychologicalCounseling = new PsychologicalCounselingService($this->app);
            if(!$PsychologicalCounseling->getOfflineRecode($data)) throw new \Exception($PsychologicalCounseling->getMessage());
            $tempResult = $PsychologicalCounseling->getResult();
            $ret['list'] = $tempResult['items'];
            $ret['total'] = $tempResult['meta']['recode_total'];
            return $ret;
        } catch (\Exception $e) {
            $this->message = $e->getMessage().$e->getLine();
            return false;
        }
    }

    /**
     * 导出线下预约记录
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportOffline($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/Offline.docx');

        //数据处理
        $list = array_values($data['list']);
        $templateProcessor->setValue('offline_title', '线下预约记录'); // 档案标题
        $templateProcessor->setValue('offline_end_time', date('Y年m月d日',$list[0][0]['end_time'])); // 档案最后更新时间

        $remark = '当前系统内共查询到，该用户相关的线下预约记录：'.$data['total'].'条。各预约记录如下：';
        $templateProcessor->setValue('record_remarkF', $remark);  //
        $situation = $this->get_situation();
        /*线下预约记录-开始*/
        $templateProcessor->cloneBlock('result_blockF', count($data['list']), true, true);
        foreach($list as $key=>$value){
            $index = $key+1;
            $templateProcessor->setValue('record_timeF#' . $index, date('Y年m月',$value[$key]['end_time']).'任务记录');  //时间
            $templateProcessor->cloneRow('numF#' . $index, count($value));
            foreach($value as $k=>$v){
                $i = $k+1;
                $templateProcessor->setValue('numF#'. $index .'#'. $i, $v['number']);//序号
                $templateProcessor->setValue('offType#'. $index .'#' . $i, $v['question_name']);//预约问题类型
                $start_time = date('Y-m-d H:i',$v['reservation_start_time']);//预约时段开始时间
                $end_time = date('H:i',$v['reservation_end_time']);//预约时段结束时间
                $time = $start_time.'-'.$end_time;
                $templateProcessor->setValue('time#'. $index .'#' . $i, $time);//预约日期和时间
                $templateProcessor->setValue('con#'. $index .'#' . $i, $v['consult_name']);//负责咨询师
                if($v['type'] ==1){
                    $type = '本人';
                }else{
                    $type = '他人';
                }
                $templateProcessor->setValue('as#'. $index .'#' . $i, $type);//预约人情况
                $templateProcessor->setValue('ay#'. $index .'#' . $i, $situation[$v['situation']]);//赴约情况
                if($v['is_end'] == 0){
                    $isEnd = '未完结';
                }else{
                    $isEnd = '已完结';
                }
                $templateProcessor->setValue('endF#'. $index .'#' . $i, $isEnd);//咨询是否完结
            }
            $templateProcessor->setValue('blankF#' . $index, ' '); //空格
        }
        /*线下预约记录-结束*/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/offline/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

    /**
     * 获取赴约情况
     * @return string[]
     */
    public function get_situation(): array
    {
        return [
            '未开始','已开始','取消预约','履约','失约'
        ];
    }

    /**
     * @param $data
     * @return string
     * @throws Exception
     */
    public function exportOfflineAll($data): string
    {
        $templateProcessor = new TemplateProcessor(app()->getRootPath().'public/archive_template/ConsultAll.docx');

        /**咨询预约概况**/
        $templateProcessor->setValue('title', '咨询预约概况'); // 档案标题
        $templateProcessor->setValue('end_time', date('Y年m月d日',$data['consult_info']['psychological']['max_time'])); // 档案最后更新时间

        /*用户基本信息-开始*/
        $this->getUserInfo($data['consult_info'],$templateProcessor);
        /*用户基本信息-结束*/

        /*咨询预约概况-开始*/
        $min_time = date('Y年m月d日',$data['consult_info']['psychological']['min_time']);
        $introduction = '本档案首次建立于：'.$min_time.'，距现在'.$data['consult_info']['psychological']['to_date'].'天。在此期间，该用户共归危机咨询/预约：'.$data['consult_info']['psychological']['total'].'次。';
        $asFollows = '咨询/预约的问题类型如下：';
        $templateProcessor->setValue('introduction', $introduction); // 介绍
        $templateProcessor->setValue('asFollows', $asFollows); // 如下

        if(empty($data['consult_info']['img'])){
            $templateProcessor->setValue('img', ''); //
        }else{
            $templateProcessor->setImageValue('img', ['path' => $data['consult_info']['img'][0], 'width' => 600, 'height' => 400]);//统计图
        }
        /*咨询预约概况-结束*/
        /**咨询预约概况**/

        /**线上咨询记录**/
        //数据处理
        if(count($data['onlineInfo_info']['list']??[]) == 0){
            //没有数据
            $templateProcessor->setValue('online_title', '线上咨询记录'); // 档案标题
            $templateProcessor->setValue('online_end_time', '暂无时间'); // 档案最后更新时间

            $remark = '当前系统内共查询到，该用户相关的线上咨询记录：0条。各咨询记录如下：';
            $templateProcessor->setValue('record_remark', $remark);  //
            /*线上咨询记录-开始*/
            $templateProcessor->cloneBlock('result_block', 1, true, true);
            $templateProcessor->setValue('record_time#1', ' ');  //时间
            $templateProcessor->setValue('num#1', ' ');//序号
            $templateProcessor->setValue('onlineType#1', ' ');//咨询问题类型
            $templateProcessor->setValue('consultantN#1', ' ');//负责咨询师
            $templateProcessor->setValue('end#1', ' ');//咨询是否完结
            $templateProcessor->setValue('endTime#1', ' ');//咨询完结时间

            $templateProcessor->setValue('blank#1' , ' '); //空格
            /*线上咨询记录-结束*/
        }
        else{
            $list = array_values($data['onlineInfo_info']['list']);
            $templateProcessor->setValue('online_title', '线上咨询记录'); // 档案标题
            $templateProcessor->setValue('online_end_time', date('Y年m月d日',$list[0][0]['end_time'])); // 档案最后更新时间

            $remark = '当前系统内共查询到，该用户相关的线上咨询记录：'.$data['onlineInfo_info']['total'].'条。各咨询记录如下：';
            $templateProcessor->setValue('record_remark', $remark);  //
            /*线上咨询记录-开始*/
            $templateProcessor->cloneBlock('result_block', count($data['onlineInfo_info']['list']), true, true);
            foreach($list as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('record_time#' . $index, date('Y年m月',$value[$key]['end_time']).'任务记录');  //时间
                $templateProcessor->cloneRow('num#' . $index, count($value));
                foreach($value as $k=>$v){
                    $i = $k+1;
                    $templateProcessor->setValue('num#'. $index .'#'. $i, $v['number']);//序号
                    $templateProcessor->setValue('onlineType#'. $index .'#' . $i, $v['question_name']);//咨询问题类型
                    $templateProcessor->setValue('consultantN#'. $index .'#' . $i, $v['consult_name']);//负责咨询师
                    if($v['is_end'] == 0){
                        $isEnd = '未完结';
                    }else{
                        $isEnd = '已完结';
                    }
                    $templateProcessor->setValue('end#'. $index .'#' . $i, $isEnd);//咨询是否完结
                    $templateProcessor->setValue('endTime#'. $index .'#' . $i, date('Y-m-d H:i:s',$v['end_time']));//咨询完结时间
                }
                $templateProcessor->setValue('blank#' . $index, ' '); //空格
            }
            /*线上咨询记录-结束*/
        }
        /**线上咨询记录**/

        /**线下预约记录**/
        if(count($data['onlineInfo_info']['list']??[]) == 0){
            //没有数据
            $templateProcessor->setValue('offline_title', '线下预约记录'); // 档案标题
            $templateProcessor->setValue('offline_end_time', '暂无时间'); // 档案最后更新时间

            $remark = '当前系统内共查询到，该用户相关的线下预约记录：0条。各预约记录如下：';
            $templateProcessor->setValue('record_remarkF', $remark);  //
            /*线下预约记录-开始*/
            $templateProcessor->cloneBlock('result_blockF', 1, true, true);
            $templateProcessor->setValue('record_timeF#1' , ' ');  //时间
            $templateProcessor->setValue('numF#1', ' ');//序号
            $templateProcessor->setValue('offType#1', ' ');//预约问题类型
            $templateProcessor->setValue('time#1', ' ');//预约日期和时间
            $templateProcessor->setValue('con#1', ' ');//负责咨询师
            $templateProcessor->setValue('as#1', ' ');//预约人情况
            $templateProcessor->setValue('ay#1', ' ');//赴约情况
            $templateProcessor->setValue('endF#1', ' ');//咨询是否完结
            $templateProcessor->setValue('blankF#1', ' '); //空格
        }
        else{
            //数据处理
            $list = array_values($data['offline_info']['list']);
            $templateProcessor->setValue('offline_title', '线下预约记录'); // 档案标题
            $templateProcessor->setValue('offline_end_time', date('Y年m月d日',$list[0][0]['end_time'])); // 档案最后更新时间

            $remark = '当前系统内共查询到，该用户相关的线下预约记录：'.$data['offline_info']['total'].'条。各预约记录如下：';
            $templateProcessor->setValue('record_remarkF', $remark);  //
            $situation = $this->get_situation();
            /*线下预约记录-开始*/
            $templateProcessor->cloneBlock('result_blockF', count($data['offline_info']['list']), true, true);
            foreach($list as $key=>$value){
                $index = $key+1;
                $templateProcessor->setValue('record_timeF#' . $index, date('Y年m月',$value[$key]['end_time']).'任务记录');  //时间
                $templateProcessor->cloneRow('numF#' . $index, count($value));
                foreach($value as $k=>$v){
                    $i = $k+1;
                    $templateProcessor->setValue('numF#'. $index .'#'. $i, $v['number']);//序号
                    $templateProcessor->setValue('offType#'. $index .'#' . $i, $v['question_name']);//预约问题类型
                    $start_time = date('Y-m-d H:i',$v['reservation_start_time']);//预约时段开始时间
                    $end_time = date('H:i',$v['reservation_end_time']);//预约时段结束时间
                    $time = $start_time.'-'.$end_time;
                    $templateProcessor->setValue('time#'. $index .'#' . $i, $time);//预约日期和时间
                    $templateProcessor->setValue('con#'. $index .'#' . $i, $v['consult_name']);//负责咨询师
                    if($v['type'] ==1){
                        $type = '本人';
                    }else{
                        $type = '他人';
                    }
                    $templateProcessor->setValue('as#'. $index .'#' . $i, $type);//预约人情况
                    $templateProcessor->setValue('ay#'. $index .'#' . $i, $situation[$v['situation']]);//赴约情况
                    if($v['is_end'] == 0){
                        $isEnd = '未完结';
                    }else{
                        $isEnd = '已完结';
                    }
                    $templateProcessor->setValue('endF#'. $index .'#' . $i, $isEnd);//咨询是否完结
                }
                $templateProcessor->setValue('blankF#' . $index, ' '); //空格
            }
            /*线下预约记录-结束*/
        }
        /**线下预约记录**/

        // 保存修改后的文档
        $ext = '.docx';
        $save_name = '/archive_template_recode/consult_all/'.date('Ym').'/'.date('d').'_'.time().uniqid();
        $file_path  = dirname(app()->getRootPath().'public'.$save_name.$ext);
        folder_build($file_path);
        $templateProcessor->saveAs(app()->getRootPath().'public'.$save_name.$ext);
        return oss(app()->getRootPath() . 'public' . $save_name . $ext, $ext);
    }

}